Figure shows the array you want sort and how the pivot chosen
618 |
|
---|
■mode - The mode of a list of numbers is the most fre- quent value in the list.
So if the median value of the array is picked as the pivot at each level in the func-tion, everything below the pivot is moved to the left, and everything above is moved to the right. The array is split exactly in half, and the quicksort is called on each half. This is the optimal way for the quicksort to operate.
Performing the Quicksort
Now that you’ve chosen the pivot, you need to do something with the array. The quicksort usually works by scanning downward and then upward, swapping num-bers if they are on the wrong side of the array.
After the array is set up, you perform a bunch of scans through the array. The first thing to do is to scan downward, starting at the last index in the array. You con-tinue scanning downward until you find a value that is lower than the pivot. At this point you stop scanning and swap that value into the empty cell.
Now, you start at the bottom of the array and scan upward looking for values larger than the pivot. Whenever you find one, it should be swapped into the empty cell.