public class Ks {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Sp sp=new Sp();
int lep=5;
int b[]=new int[lep];
for(int i=0;i<lep;i++) {
int t=(int)(Math.random()*100);
b[i]=t;
}
for(int i=0;i<b.length;i++) {
System.out.print(b[i]+" ");
}
System.out.println("\n");
sp.sp(0, b.length-1, b);
for(int i=0;i<b.length;i++) {
System.out.print(b[i]+" ");
}
}
}
public void sp(int left,int right,int b[]) {
int l=left;
int r=right;
int z=b[(left+right)/2];
int temp=0;
while(l<r){
while(b[l]<z) l++;
while(b[r]>z) r--;
if(l>=r) break;
temp=b[l];
b[l]=b[r];
b[r]=temp;
if(b[l]==z) --r;
if(b[r]==z) ++l;
}
if(l==r){
l++;
r--;
}
if(left<r) sp(left,r,b);
if(right>l) sp(l,right,b);
}
}