您的位置:首页 > 其它

侏儒排序

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-- ;
}
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: