自己整理的排序算法(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]+" ");
		}
	}
}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM