![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
static
int
Partition(
int
[] array,
int
low,
int
high)
{
int pivot = array[low];
while (low < high)
{
while (low < high && array[high] >= pivot)
{
high -- ;
}
if (low != high)
{
swap( ref array[low], ref array[high]);
}
while (low < high && array[low] <= pivot)
{
low ++ ;
}
if (high != low)
{
swap( ref array[high], ref array[low]);
}
}
return low;
}
static void QSort( int [] array, int low, int high)
{
if (low < high)
{
int pivotloc = Partition(array, low, high);
QSort(array, low, pivotloc - 1 );
QSort(array, pivotloc + 1 , high);
}
}
static void QuickSort( int [] array)
{
QSort(array, 0 , array.Length - 1 );
}
static void swap( ref int a, ref int b)
{
int temp = a;
a = b;
b = temp;
}
static void Main( string [] args)
{
int [] a = new int [] { 6 , 2 , 5 , 3 , 1 , 4 , 7 };
QuickSort(a);
}
{
int pivot = array[low];
while (low < high)
{
while (low < high && array[high] >= pivot)
{
high -- ;
}
if (low != high)
{
swap( ref array[low], ref array[high]);
}
while (low < high && array[low] <= pivot)
{
low ++ ;
}
if (high != low)
{
swap( ref array[high], ref array[low]);
}
}
return low;
}
static void QSort( int [] array, int low, int high)
{
if (low < high)
{
int pivotloc = Partition(array, low, high);
QSort(array, low, pivotloc - 1 );
QSort(array, pivotloc + 1 , high);
}
}
static void QuickSort( int [] array)
{
QSort(array, 0 , array.Length - 1 );
}
static void swap( ref int a, ref int b)
{
int temp = a;
a = b;
b = temp;
}
static void Main( string [] args)
{
int [] a = new int [] { 6 , 2 , 5 , 3 , 1 , 4 , 7 };
QuickSort(a);
}