public class MyQuickSort {
/**快速排序
* @param args
*/
int Partition(int[] strVoid,int low ,int hight)
{
int middle = (hight+low)/2;
int temp ;
do{
while(strVoid[middle]<strVoid[hight] && hight>low)
{
hight--;
}
while(strVoid[middle]>strVoid[low] && low<hight)
{
low++;
}
if(low <= hight)
{
if(low == middle)
{
middle = hight; //交换时,涉及middle 必须记录交换后middle的位置
}else if(hight==middle)
{
middle = low;
}
temp = strVoid[hight];
strVoid[hight] = strVoid[low];
strVoid[low] = temp;
low++;
}
}while(low<=hight);
return middle;
}
void myQuickSort(int[] strVoid,int low ,int hight){
int middle;
if(low<hight){
middle = Partition( strVoid,low,hight);
myQuickSort(strVoid,low,middle-1);
myQuickSort(strVoid,middle+1,hight);
}
}
public static void main(String[] args) {
int[] strVoid=new int[]{11,66,22,10,55,22,0,32};
MyQuickSort mq = new MyQuickSort();
mq.myQuickSort(strVoid,0,strVoid.length-1);
for(int i=0;i<strVoid.length;i++)
{
System.out.print(strVoid[i]+" ");
}
}
}