没有限定算法,一开始用的冒泡,超时,改用了快速排序
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
* 将给定数组排序
* @param arr int整型一维数组 待排序的数组
* @param arrLen int arr数组长度
* @return int整型一维数组
* @return int* returnSize 返回数组行数
*/
int getIndex(int *arr,int low,int high)
{
int temp = arr[low];
while(low<high)
{
while(low<high && arr[high] >= temp)
high--;
arr[low] = arr[high];
while(low<high && arr[low] <= temp)
low++;
arr[high] = arr[low];
}
arr[low] = temp;
return low;
}
void quickSort(int *arr,int low,int high)
{
int index = 0;
if(low<high)
{
index = getIndex(arr,low,high);
quickSort(arr, low, index-1);
quickSort(arr, index+1, high);
}
}
int* MySort(int* arr, int arrLen, int* returnSize )
{
// write code here
quickSort(arr, 0, arrLen-1);
*returnSize = arrLen;
return arr;
}