Dale - Computer Science Illuminated 320

Dale - Computer Science Illuminated 320 - 9.4 Sorting 293...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
9.4 Sorting 293 After the call to Split , all the items less than or equal to splitVal are on the left side of the list and all of those greater than splitVal are on the right side of the list. The two “halves” meet at splitPoint , the index of the last item that is less than or equal to splitVal . Note that we don’t know the value of splitPoint until the splitting process is complete. We can then swap splitVal (list[first]) with the value at list[splitPoint] . Our recursive calls to Quicksort use this index ( splitPoint ) to reduce the size of the problem in the general case. Quicksort(first, splitPoint 1) sorts the left “half” of the list. Quicksort(split- Point + 1, last) sorts the right “half” of the list. (The “halves” are not neces- sarily the same size.) splitVal is already in its correct position in list[splitPoint] . What is the base case? When the segment being examined has only one item, we do not need to go on.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.
Ask a homework question - tutors are online