Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. int QuickSort(int low, int high)
  2. {
  3. int pivot;
  4. int i;
  5. int j;
  6. while (left <= right)
  7. {
  8. if (high <= low + 1)
  9. {
  10. if (high == low + 1 && buff[high] < buff[low])
  11. swap (buff[low], buff[high]);
  12. return buff[k];
  13. }
  14.  
  15. int mid = (low + high) / 2;
  16. swap (buff[mid], buff[low + 1]);
  17. if (buff[low] > buff[high])
  18. swap (buff[low], buff[high]);
  19. if (buff[low + 1] > buff[high])
  20. swap (buff[low + 1], buff[high]);
  21. if (buff[low] > buff[low + 1])
  22. swap (buff[low], buff[low + 1]);
  23.  
  24. pivot = buff[low + 1];
  25. i = low + 1;
  26. j = high;
  27.  
  28. while (i <= j)
  29. {
  30. while (buff[++i] < pivot);
  31. while (buff[--j] > pivot);
  32. if (i > j) break;
  33. swap(buff[i], buff[j]);
  34. }
  35. swap(buff[j], buff[low + 1]);
  36. if (j >= k) high = j - 1;
  37. if (i <= k) low = i;
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement