62,628
社区成员
发帖
与我相关
我的任务
分享public class KuaiPai {
public static void main(String[] args) {
int[] s={9,8,7,5,6,7,4,4,1};
sort(s);
for(int i:s){
System.out.print(i);
}
}
public static void sort(int [] s){
sort(s,0,s.length-1);
}
public static void sort(int []s,int first,int last){
if(last>first){
int index=part(s,first,last);
sort(s,first,index-1);
sort(s,index+1,last);
}
}
public static int part(int[] s,int first,int last){
int key=s[first];
int low=first+1;
int high=last;
while(high>low){
while(low<=high&&s[low]<=key){
low++;
}
while(low<=high&&s[high]>key)
high--;
if(high>low){
int temp=s[low];
s[low]=s[high];
s[high]=temp;
}
}
//这一段的意义在哪?
while(high>first&&s[high]>=key){
high--;
}
if(key>s[high]){
s[first]=s[high];
s[high]=key;
return high;
}else{
return first;
}
}
}