选择排序 (Selection Sort)

来源:互联网 发布:谁有午夜福利软件 编辑:程序博客网 时间:2024/05/22 09:58

选择排序的基本思想是:对待排序的记录序列进行n-1遍的处理,第1遍处理是将L[1..n]中最小者与L[1]交换位置,第2遍处理是将L[2..n]中最小者与L[2]交换位置,......,第i遍处理是将L[i..n]中最小者与L[i]交换位置。这样,经过i遍处理之后,前i个记录的位置就已经按从小到大的顺序排列好了。

 

平均时间复杂度:O(n2)

 

Java Code:

public class SelectionSort {public static float[] SlectionSortAlgorithm(float flt[], int length){float sortedFlt[]=flt;for(int i=0;i<length-1;i++){float temp=flt[i];for(int j=i+1;j<length;j++){if(flt[j]<flt[i]){flt[i]=flt[j];flt[j]=temp;}}}return sortedFlt;}}


原创粉丝点击