Selection Sort
1. Declare items an array for a list of values.
2. Echo(output) the unsorted values.
3. Visualize the items array as containing a part that is sorted and another
part that is unsorted.
Selection sort algorithm:
set firstUnsortedIndex to 0;
while (not sorted yet)
find smallest* unsorted
swap firstUnsorted value in items with the smallest value
increment firstUnsortedIndex
Not sorted yet:
firstUnsortedIndex < length - 1
*Find smallest unsorted name:
set indexOfSmallest to firstUnsortedIndex
set index to firstUnsortedIndex + 1
while (index <= length - 1)
if (items[index]->getName() < items[indexOfSmallest]-getName())
set indexOfSmallest to index
set index to index+1
Swap firstUnsortedName with smallest
set tempValue to items[firstUnsortedIndex] // save value
set items[firstUnsortedIndex] to items[indexOfSmallest]
set items[indexOfSmallest] to tempValue
*smallest means earliest/lowest in alphabetical order
4. Output the sorted values.