public class QuickS {
public static void main(String[] args) {
int arr[]={9,5,58,24,3,15,6,55,7,56,45,2};
sort(arr,0,arr.length-1);
StringBuilder sb=new StringBuilder();
for (int i = 0; i < arr.length; i++) {
sb.append(arr[i]);
sb.append(",");
}
System.out.println(sb.toString());
}
public static void sort(int [] array,int low,int high){
int l=low;
int h=high;
int mark=array[l];
System.out.println("l="+l+", h="+h+" mark="+mark);
while (l<h) {
while (l < h && array[h] > mark) h--;
if(l<h) {
int temp = array[h];
array[h] = array[l];
array[l] = temp;
}
while(l<h&&array[l]<mark)l++;
if(l<h){
int temp=array[h];
array[h]=array[l];
array[l]=temp;
}
}
if(l>low)sort(array,low,l-1);
if(h<high)sort(array,h+1,high);
}
}
快速排序
最新推荐文章于 2021-11-19 16:57:43 发布