Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. public static int partition(int arr[], int left, int right) {
  2. // Pick a pivot point. Can be any element.
  3. int pivot = arr[(left + right) / 2];
  4.  
  5. while (left <= right) {
  6. while (arr[left] < pivot) {
  7. left++;
  8. }
  9.  
  10. while (arr[right] > pivot) {
  11. right--;
  12. }
  13.  
  14. if (left <= right) {
  15. swap(arr, left, right);
  16. left++;
  17. right--;
  18. }
  19. }
  20.  
  21. return left;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement