侏儒排序

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

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章