Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A Utility function to perform intro sort
- void IntrosortUtil(int arr[], int * begin,int * end, int depthLimit)
- {
- // Count the number of elements
- int size = end - begin;
- // If partition size is low then do insertion sort
- if (size < 16)
- {
- InsertionSort(arr, begin, end);
- return;
- }
- // If the depth is zero use heapsort
- if (depthLimit == 0)
- {
- make_heap(begin, end+1);
- sort_heap(begin, end+1);
- return;
- }
- // Else use a median-of-three concept to
- // find a good pivot
- int * pivot = MedianOfThree(begin, begin+size/2, end);
- // Swap the values pointed by the two pointers
- swapValue(pivot, end);
- // Perform Quick Sort
- int * partitionPoint = Partition(arr, begin-arr, end-arr);
- IntrosortUtil(arr, begin, partitionPoint-1, depthLimit - 1);
- IntrosortUtil(arr, partitionPoint + 1, end, depthLimit - 1);
- return;
- }`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement