using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QuickSortobj2
{
class Program
{
static int Partition(int[] data, int left,int right)
{
int temp = data[left];
int start = left - 1;
int end = right + 1;
while(start + 1 != end)
{
if(data[start+1] <= temp)
start++;
else if(data[end-1] > temp)
end--;
else
{
int tmp=data[start+1];
data[++start]=data[end-1];
data[--end]=tmp;
}
}
data[left] = data[start];
data[start] = temp;
return start;
}
static void Quicksort(int[] data, int left,int right)
{
int midIndex;
if (left<right)
{
midIndex = Partition(data, left, right);
Quicksort(data, left, midIndex - 1);
Quicksort(data, midIndex + 1, right); //这两个就是递归调用,分别整理53左边的数组和右边的数组
}
}
static void Main(string[] args)
{
int[] data = new int[10];//{1,56,25,32,41,20,10,30,75,59};
for (int i = 0; i < data.Length; i++)
data[i] = Convert.ToInt32(Console.ReadLine());
Quicksort(data, 0, data.Length - 1);
foreach (int i in data)
Console.Write(" " + i);
Console.ReadKey();
}
}
}