java实现快速排序,好不容易,写下来吧
public static int sortxp(int[] hashint,int offset,int endset)
{
int key=hashint[offset];
int index=offset;
int swint=0;
if(hashint.length<2)
{
return 0;
}
for(int begin=offset,end=endset;begin!=end;)
{
while(begin!=end&&hashint[end]>key)
{
end--;
}
if(hashint[end]<key)
{
swint=hashint[end];
hashint[end]=hashint[index];
hashint[index]=swint;
index=end;
}
while(begin!=end&&hashint[begin]<key)
{
begin++;
}
if(hashint[begin]>key)
{
swint=hashint[begin];
hashint[begin]=hashint[index];
hashint[index]=swint;
index=begin;
}
}
return index;
}
public static void sortquz(int[] hashint,int offset,int endset)
{
if(endset-offset<1)
{
return;
}
int index=sortxp(hashint, offset, endset);
sortquz(hashint,offset,index-1);
sortquz(hashint,index+1,endset);
}
public static void main(String[] args)
{
int[] all={49,38,65,97,76,13,27,108,222,11,48,37,64,976,75,12,26,107,221,10};
sortquz(all, 0, all.length-1);
for(int i=0;i<all.length;i++)
{
System.out.println(all[i]);
}
}