import java.util.Stack;
public static final int[] quickSort(int[] data){
  Stack stack=new Stack();
  int temp;
  int i,j,left,right;
  stack.push(new Integer(data.length-1)); //push right
  stack.push(new Integer(0)); //push left
  do{
    left=((Integer)stack.pop()).intValue();  //pop left
    right=((Integer)stack.pop()).intValue(); //pop right
    i=left+1;
    j=right;
    while(j>i){
      while(data[i] < data[left])
        if(i data[left])
        if(j>left+1) j--;
        else break;
      if(j>i){
        temp = data[j];
        data[j] = data[i];
        data[i] = temp;
      }
    }
    if(data[j] < data[left]){
      temp = data[j];
      data[j] = data[left];
      data[left] = temp;
    }
    if(j>left){
      stack.push(new Integer(j-1)); // push right
      stack.push(new Integer(left)); // push left
    }
    if(j0);
  return data;
}

解决方案 »

  1.   

    public static void QuickSort(int Left,int Right,int Index){
      int i,j,k;
      int Pivot;
      int Temp;
      
      i=Left;
      j=Right+1;
      Pivot=Data[Left];
      if(i<j){
        do{
           do{
              i++;
             }while(Data[i]<=Pivot&&i<=Right);
           do {
               j--;
              }while(Data[i]>=Pivot&&j>Left);
         
           if(i<j){
               Temp=Data[i];
               Data[i]=Data[j];
               Data[j]=Temp;
               }
              }while(i<j);
            if(i>j){
               Temp=Data[Left];
               Data[Left]=Data[j];
               Data[j]=Temp;
               System.out.print("Current sorting result:");
               for(k=0;k<Index;k++){
                  System.out.print(""+Data[k]+"");
               }
               System.out.println("");
              }
              QuickSort(Left,j-1,Index);
              QuickSort(j+1,Right,Index);
             }
         }
    }
      

  2.   

    数组对象中本来就有Sort方法,用的就是快排,呵呵。int[] a=new int[10000]
    ...
    Array.sort(a)