Unformatted text preview: alphabet. The process of remembering the smallest so far until you find a smaller one is repeated until you reach the end of the list. This by-hand algorithm is exactly the one we use here. Only we must remember the index of the smallest because we are going to swap that item with the item in the current position. So in terms of our list, we look for the smallest in the unsorted portion, which runs from current through length – 1 . Find the index of the smallest Set indexOfSmallest to current For index going from current + 1 to length ± 1 If (list[index].compareTo(list[indexOfSmallest]) < 0) Set indexOfSmallest to index No sorted yet current < length ± 1 Selection Sort Set current to the index of first item in the list While ( not sorted yet ) Find the index of the smallest unsorted item Swap the current item with the smallest unsorted one Incrementing current to shrink unsorted part...
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