快速排序和运用的场景 java语言

 

选择排序:稳定

适用于:数据量大的情况。

public class QuickSortP252 {
public static void main(String[] args) {
int[] a= {5,4,9,8,7,6,0,1,3,2};
quickSort(a);
System.out.println(Arrays.toString(a));
}
public static void sort(int[] array,int low,int hight) {
int l=low;
int h=hight;
int flage=array[l];
while(l<h) {
while(l<h&&array[h]>=flage) {
h--;
}
if(array[h]<flage) {
array[l]=array[h];
l++;
}
while(l<h&&array[l]<=flage) {
l++;
}

if(array[l]>flage) {
array[h]=array[l];
h--;
}
array[l]=flage;
sort(array,low,l-1);
sort(array,l+1,hight);

}

}
public static void quickSort(int[] a) {
sort(a,0,a.length-1);
}

 

posted @ 2019-04-26 15:20  上官蓓儿  阅读(698)  评论(0编辑  收藏  举报