![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
public
static
void
QuickSort(
int
[] array,
int
left,
int
right)
{
do
{
int a = left;
int b = right;
int num3 = a + ((b - a) >> 1 ); // a+(b-a)/2
SwapIfCreater(array, a, num3);
SwapIfCreater(array, a, b);
SwapIfCreater(array, num3, b);
do
{
while (array[a] < array[num3])
{
a ++ ;
}
while (array[num3] < array[b])
{
b -- ;
}
if (a > b)
{
break ;
}
if (a < b)
{
int temp = array[a];
array[a] = array[b];
array[b] = temp;
}
a ++ ;
b -- ;
}
while (a <= b);
if ((b - left) <= (right - a))
{
if (left < b)
{
QuickSort(array, left, b);
}
left = a;
}
else
{
if (a < right)
{
QuickSort(array, a, right);
}
right = b;
}
} while (left < right);
}
{
do
{
int a = left;
int b = right;
int num3 = a + ((b - a) >> 1 ); // a+(b-a)/2
SwapIfCreater(array, a, num3);
SwapIfCreater(array, a, b);
SwapIfCreater(array, num3, b);
do
{
while (array[a] < array[num3])
{
a ++ ;
}
while (array[num3] < array[b])
{
b -- ;
}
if (a > b)
{
break ;
}
if (a < b)
{
int temp = array[a];
array[a] = array[b];
array[b] = temp;
}
a ++ ;
b -- ;
}
while (a <= b);
if ((b - left) <= (right - a))
{
if (left < b)
{
QuickSort(array, left, b);
}
left = a;
}
else
{
if (a < right)
{
QuickSort(array, a, right);
}
right = b;
}
} while (left < right);
}
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
private
static
void
SwapIfCreater(
int
[] array,
int
a,
int
b)
{
if (a != b && array[a] > array[b])
{
int temp = array[a];
array[a] = array[b];
array[b] = temp;
}
}
{
if (a != b && array[a] > array[b])
{
int temp = array[a];
array[a] = array[b];
array[b] = temp;
}
}