Home c++ Quick Sort Descending on C

Quick Sort Descending on C




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])
    if (low & gt; = high)
    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


part_element & gt; = a [high]
a [low] & gt; = part_element

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions