手搓快排
快速排序是十分常用的高效率的算法
时间复杂度为O(nlogn),空间复杂度为O(n)
代码如下:
public void QuickSort(int[] arry, int top, int tail)
{
if (top >= tail) return;
int i = top;
int j = tail;
int temp = arry[top];
while (i < j)
{
while(i<j && arry[j] >= temp) j--;
if (i < j) arry[i] = arry[j];
else
{
arry[i] = temp;
break;
}
while (i < j && arry[i] <= temp) i++;
if (i < j) arry[j] = arry[i];
else
{
arry[i] = temp;
break;
}
}
arry[i] = temp;
QuickSort(arry, 0, i - 1);
QuickSort(arry, i + 1, tail);
}