自己整理的排序算法(2)用递归实现选择排序

//用递归的方法实现选择排序
package sort;

public class RecursiveSelectionSort {
	public static void sort(double[] list){
		sort(list,0,list.length-1);
	}
	
	public static void sort(double[] list,int low,int high){
		if(low<high){
		 double	currentMin = list[low];
		 int currentMinIndex = low;
		 
		 for(int i = low+1;i<=high;i++){
			 if(currentMin>list[i]){
				 currentMin = list[i];
				 currentMinIndex = i;
			 }
		 }
		 
			 list[currentMinIndex ] = list[low];
			 list[low] = currentMin;
			 
		 sort(list,low+1,high);
		}
	}
	
	public static void main(String[] args){
		double[] list ={5.2 , 1.4 , 6.3,  2.3  ,4.6};
		sort(list);
		for(int i =0;i<list.length;i++){
			System.out.print(list[i]+" ");
		}
	}
}

  

posted @ 2016-09-07 21:55  小竹子kisty  阅读(3085)  评论(0编辑  收藏  举报