侏儒排序
2015-08-08 20:47
288 查看
import java.math.* ; import java.util.* ; /** * */ public class Test extends Base{ public static void main(String[] args) throws Exception{ int[] arr = getRandomArr() ; println(arr); gnomeSort(arr , arr.length ); println(arr); println(); } public static void gnomeSort(int[] arr, int n ){ int pos = 1 ; int temp ; while (pos < n){ if(arr[pos] >= arr[pos - 1]){ pos++ ; } else { temp = arr[pos] ; arr[pos] = arr[pos - 1] ; arr[pos - 1] = temp ; if(pos > 1) pos-- ; } } } }
相关文章推荐
- 简单工厂VS工厂方法
- 安卓开发-传感器信息采集
- hdoj 5087 Revenge of LIS II 【第二长单调递增子】
- POJ 2407 Relatives(欧拉函数)
- 黑马程序员——Java中的一个关于参数传递的小问题
- Hibernate使用
- 九度OJ 题目1001:A+B for Matrices
- 【JS设计模式】简单工厂模式
- poj 3041 Asteroids(最小点覆盖)
- uva 331 Mapping the Swaps
- HDU 1846 Brave Game
- nginx、gunicorn、supervisor三个来共同协作搭建网站出现问题
- Java-----读、写文件的几种方法
- 【JS设计模式】命令模式
- 【JS设计模式】组合模式
- 【常用】C#万年历代码
- 2015多校6
- 在ubuntu12.04下编译android4.1.2添加JNI层出现问题
- HDOJ 1009
- LightOJ 1002 Country Roads(最短路变形(SPFA||贝尔曼))