using System;
public class HelloWorld
{
public static void Main()
{
int[] a = { 5, 4, 9, 8, 7, 6, 0, 1, 3, 2 };
int len = a.Length;
sort(a, 0, a.Length - 1);
foreach (int i in a)
{
Console.Write($"{i} ");
}
}
static void sort(int[] array, int low, int high)
{
if (low >= high)
{
return;
}
// 基准值 选取当前数组第一个值
int temp = array[low];
// 低位i从左向右扫描
int i = low;
// 高位j从右向左扫描
int j = high;
while (i < j)
{
while (i < j && array[j] >= temp)
{
j--;
}
if (i < j)
{
array[i] = array[j];
i++;
}
while (i < j && array[i] < temp)
{
i++;
}
if (i < j)
{
array[j] = array[i];
j--;
}
}
array[i] = temp;
// 左边的继续递归排序
sort(array, low, i - 1);
// 右边的继续递归排序
sort(array, i + 1, high);
}
}