using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] a={3,2,5,1};
QuickSort(a, 0, a.Length - 1);
for (int i = 0; i < a.Length; i++)
{
Console.WriteLine(a[i]);
}
Console.ReadLine();
}
public static void QuickSort(int[] array, int left, int right)
{
int origin_right = right;
int origin_left = left;
if (left>=right)
{
return;
}
bool transfer = true;
while (left<right)
{
if (array[left]>array[right])
{
int tmp = array[left];
array[left] = array[right];
array[right] = tmp;
transfer = (transfer == true) ? false : true;
}
if (transfer)
{
right--;
}
else
{
left++;
}
}
QuickSort(array, origin_left, left - 1);
QuickSort(array, right + 1, origin_right);
}
}
}