Unformatted text preview: 288 Chapter 9 Abstract Data Types and Algorithms Figure 9.9 Example of selection sort (sorted elements are shaded) RFz R&amp;#18;z R9z R&amp;#20;z Rhz Sue items Cora Beth Ann June (a) RFz R&amp;#18;z R9z R&amp;#20;z Rhz Ann items Cora Beth Sue June (b) RFz R&amp;#18;z R9z R&amp;#20;z Rhz Ann items Beth Cora Sue June (c) RFz R&amp;#18;z R9z R&amp;#20;z Rhz Ann items Beth Cora Sue June (d) RFz R&amp;#18;z R9z R&amp;#20;z 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
This note was uploaded on 01/13/2011 for the course CSE 1550 taught by Professor Marianakant during the Fall '10 term at York University.
- Fall '10