Dale - Computer Science Illuminated 315

Dale - Computer Science Illuminated 315 - 288 Chapter 9...

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 288 Chapter 9 Abstract Data Types and Algorithms Figure 9.9 Example of selection sort (sorted elements are shaded) RFz Rz R9z Rz Rhz Sue items Cora Beth Ann June (a) RFz Rz R9z Rz Rhz Ann items Cora Beth Sue June (b) RFz Rz R9z Rz Rhz Ann items Beth Cora Sue June (c) RFz Rz R9z Rz Rhz Ann items Beth Cora Sue June (d) RFz Rz R9z Rz Rhz Ann items Beth Cora June Sue (e) In this section we present several quite different sorting algorithms to give you a flavor of how many different ways there are to solve the same problem. The language of sorting algorithms uses array-based notation because each item to be sorted must be accessed directly by its index, not through the item before it. In the sections that follow, we use compareTo to compare two items. Selection Sort The selection sort algorithm is probably the easiest because it mirrors how we would sort a list of values if we had to do it by hand. If you were handed a list of names and asked to put them in alphabetical order, you...
View Full Document

Ask a homework question - tutors are online