public void quickSort(){
recQuickSort(0,nElems-1);
}
public void recQuickSort(int left, int right){
if(right-left<=0){
return;
}else{
long pivot = theArray[right];
int partition = partitionIt(left, right, pivot);
recQuickSort(left, partition-1);
recQuickSort(partition+1, right);
}
}
public int partitionIt(int left, int right, long pivot){
int leftPtr = left -1;
int rightPtr = right;
while(true){
while(theArray[++leftPtr]
while(rightPtr>0&&theArray[--rightPtr]>pivot);
if(leftPtr>=rightPtr){
break;
}else{
swap(leftPtr,rightPtr);
}
}swap(leftPtr,right);
return leftPtr;
}
public void swap(int dex1, int dex2){
long temp;
temp = theArray[dex1];
theArray[dex1]=theArray[dex2];
theArray[dex2]=temp;
}
分享到:
2010-04-15 09:18
浏览 968
评论