CS 210 Analysis & Design for Selection Sort Algorithm
Function: SortArray
Analysis
Objects Type Movement Name
--------------------------------------------------------
array to be sorted double[ ] received
passed back anArray
# of elements in array int received count
index of smallest element int local indexOfSmallest
index counter int local pass
Design
1. For pass from 0 to count-2 by 1 do
1.1 Compute indexOfSmallest =
FindIndexOfSmallest (anArray, pass, count)
1.2 Exchange values at pass and indexOfSmallest using
Swap (anArray[pass], anArray[indexOfSmallest])
Function: FindIndexOfSmallest
Analysis
Objects Type Movement Name
--------------------------------------------------------
array to be searched double[ ] received anArray
index to start search int received startIndex
# of elements in array int received count
index of smallest element int returned indexOfSmallest
index counter int local i
Design
1. Initialize indexOfSmallest to startIndex,
2. For i from startIndex+1 to count - 1 by 1 do
2.1 If anArray[i] < a[indexOfSmallest] then
2.1.1 Set indexOfSmallest to i
3. Return indexOfSmallest
Last modified October 19, 2006