Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int QuickSort(int low, int high)
- {
- int pivot;
- int i;
- int j;
- while (left <= right)
- {
- if (high <= low + 1)
- {
- if (high == low + 1 && buff[high] < buff[low])
- swap (buff[low], buff[high]);
- return buff[k];
- }
- int mid = (low + high) / 2;
- swap (buff[mid], buff[low + 1]);
- if (buff[low] > buff[high])
- swap (buff[low], buff[high]);
- if (buff[low + 1] > buff[high])
- swap (buff[low + 1], buff[high]);
- if (buff[low] > buff[low + 1])
- swap (buff[low], buff[low + 1]);
- pivot = buff[low + 1];
- i = low + 1;
- j = high;
- while (i <= j)
- {
- while (buff[++i] < pivot);
- while (buff[--j] > pivot);
- if (i > j) break;
- swap(buff[i], buff[j]);
- }
- swap(buff[j], buff[low + 1]);
- if (j >= k) high = j - 1;
- if (i <= k) low = i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement