java快速排序函数

类别:Java 点击:0 评论:0 推荐:

      void QuickSort(String[] pData,int[] pDataNum,int left,int right)
      {
        int i,j;
        int iTemp;
        String middle,strTemp;
        i = left;
        j = right;
        middle = pData[(left+right)/2];
        do{
          while((pData[i].compareTo(middle)<0) && (i<right))
            i++;     
          while((pData[j].compareTo(middle))>0 && (j>left))
            j--;
          if(i<=j)
          {
            strTemp = pData[i];
            pData[i] = pData[j];
            pData[j] = strTemp;
           
            iTemp = pDataNum[i];
            pDataNum[i] = pDataNum[j];
            pDataNum[j] = iTemp;
           
            i++;
            j--;
          }
        }while(i<=j);//如果两边扫描的下标交错,就停止(完成一次)

        if(left<j)
          QuickSort(pData,pDataNum,left,j);

        if(right>i)
          QuickSort(pData,pDataNum,i,right);
      }

本文地址:http://com.8s8s.com/it/it14128.htm