using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 快速排序
{
class Program
{
static void Main(string[] args)
{
int[] array = new[] { 6, 7, 2, 1, 9, 4, 3, 10, 5, 8 };
Sort(array, 0, array.Length-1);
for (int i = 0; i < array.Length; i++)
{
Console.Write(" " + array[i]);
}
Console.ReadKey();
}
public static void Sort(int[] array, int left, int right)
{
if (left < right)
{
int x = array[left];
int i = left;
int j = right;
while (i < j)
{
while (i < j)
{
if (array[j] <= x)
{
array[i] = array[j];
break;
}
else
{
j--;
}
}
while (i < j)
{
if (array[i] > x)
{
array[j] = array[i];
break;
}
else
{
i++;
}
}
}
array[i] = x;
Sort(array, left, i - 1);
Sort(array, i + 1, right);
}
}
}
}