题解 | #排序#
排序
http://www.nowcoder.com/practice/2baf799ea0594abd974d37139de27896
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
* 将给定数组排序
* @param arr int整型一维数组 待排序的数组
* @return int整型一维数组
*/
public int[] MySort (int[] arr) {
// write code here
Sort(arr,0,arr.length-1);
return arr;
}
private void Sort(int[] arr ,int low,int top){
if(low<top){
int swap;
int begin=low;
int j=top;
while(low<top){
while(arr[top]>=arr[begin]&&low<top) top--;
while(arr[low]<=arr[begin]&&low<top) low++;
swap=arr[top];
arr[top]=arr[low];
arr[low]=swap;
}
swap=arr[begin];
arr[begin]=arr[low];
arr[low]=swap;
Sort(arr,begin,low-1);
Sort(arr,low+1,j);
}
}
}
