public class quickSort {
public int a[]=new int[5];
quickSort(){
a[0]=1;
a[1]=4444;
a[2]=8;
a[3]=2;
a[4]=10;}
public void sort(int left,int right){
if(left>=right)
return;
int temp,i=left,j=right,k;
temp=a[left];
while(i!=j)
{ while(a[j]>=temp&&i<j)
j--;
while(a[i]<=temp&&i<j)
i++;
if(i<j)
{
k=a[i];
a[i]=a[j];
a[j]=k;
}
}
a[left]=a[i];
a[i]=temp;
sort(left,i-1);
sort(i+1,right);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
quickSort aa=new quickSort();
aa.sort( 0, 4);
for(int ww=0;ww<5;ww++)
System.out.println(aa.a[ww]);
}
}
快速排序
最新推荐文章于 2024-07-17 10:35:12 发布