题解 | #排序#
排序
http://www.nowcoder.com/practice/2baf799ea0594abd974d37139de27896
public int[] MySort (int[] arr) {
// write code here
QuickSort(arr,0,arr.length-1);
return arr;
}
int Partition(int[] arr,int low,int high){
int pivot=arr[low];
while(low<high){
while(low<high&&arr[high]>=pivot)--high;
arr[low]=arr[high];
while(low<high&&arr[low]<=pivot)++low;
arr[high]=arr[low];
}
arr[low]=pivot;
return low;
}
void QuickSort(int[]arr,int low ,int high){
if(low<high){
int pivotpos=Partition(arr,low,high);
QuickSort(arr,low,pivotpos-1);
QuickSort(arr,pivotpos+1,high);
}