Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. // A Utility function to perform intro sort
  2. void IntrosortUtil(int arr[], int * begin,int * end, int depthLimit)
  3. {
  4. // Count the number of elements
  5. int size = end - begin;
  6.  
  7. // If partition size is low then do insertion sort
  8. if (size < 16)
  9. {
  10. InsertionSort(arr, begin, end);
  11. return;
  12. }
  13.  
  14. // If the depth is zero use heapsort
  15. if (depthLimit == 0)
  16. {
  17. make_heap(begin, end+1);
  18. sort_heap(begin, end+1);
  19. return;
  20. }
  21.  
  22. // Else use a median-of-three concept to
  23. // find a good pivot
  24. int * pivot = MedianOfThree(begin, begin+size/2, end);
  25.  
  26. // Swap the values pointed by the two pointers
  27. swapValue(pivot, end);
  28.  
  29. // Perform Quick Sort
  30. int * partitionPoint = Partition(arr, begin-arr, end-arr);
  31. IntrosortUtil(arr, begin, partitionPoint-1, depthLimit - 1);
  32. IntrosortUtil(arr, partitionPoint + 1, end, depthLimit - 1);
  33.  
  34. return;
  35. }`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement