I have the goal to convert the source code ascending quick sort, in exactly the same, but in descending order.
Do not quite understand how this code works (Got a lecture)
int split (int a [], int low, int high)
{
int part_element = a [low];
for (;;)
{
while (low & lt; high & amp; & amp; part_element & lt; = a [high])
high--;
if (low & gt; = high)
break;
a [low ++] = a [high];
while (low & lt; high & amp; & amp; a [low] & lt; = part_element)
low ++;
if (low & gt; = high) break;
a [high--] = a [low];
}
a [high] = part_element;
return high;
}
void QuickSort (int a [], int low, int high)
{
int middle;
if (low & gt; = high) return;
middle = split (a, low, high);
QuickSort (a, low, middle - 1);
QuickSort (a, middle + 1, high);
}
Answer 1, authority 100%
How does it work – just recursively divides each array so that when left to an element are all elements smaller than him, and the right – more. And so to the array of 1 element.
A simple change to sort itself – to replace two comparisons of the support member on the reverse:
part_element & lt; = a [high]
a [low] & lt; = part_element
The
part_element & gt; = a [high]
a [low] & gt; = part_element