barzini
06-20-2009, 09:45 AM
I need help to create an algorithm for the selection sort, show it as pseudocode OR a flowchart, and desk check with the same two sets of values.
The outer loop repeats the selection process n-1 times. For each iteration it is initially assumed that the first entry (index 0) contains the highest value (max = 0). The inner loop then examines the array from left to right and whenever a higher value is found, it's locations in the list is stored in the value "max".
At the end of the first iteration, the last entry in the list has it's value swapped with the entry containing the highest value. The counter of the outer loop is then decremented, so the next highest value will be correctly located, and so on until only the first two are compared and swapped if necessary.
The outer loop repeats the selection process n-1 times. For each iteration it is initially assumed that the first entry (index 0) contains the highest value (max = 0). The inner loop then examines the array from left to right and whenever a higher value is found, it's locations in the list is stored in the value "max".
At the end of the first iteration, the last entry in the list has it's value swapped with the entry containing the highest value. The counter of the outer loop is then decremented, so the next highest value will be correctly located, and so on until only the first two are compared and swapped if necessary.