|
|
|
|
|
|
|
Figure 12-3
Straight Selection Sort |
|
|
|
|
|
|
|
|
Two parameters are needed for the selection sort function: the array containing the list to be sorted and the length of the list. The code for this sorting algorithm is: |
|
|
|
|
|
|
|
|
void SelSort( /* inout */ ItemType list[], // List to be sorted
/* in */ int length ) // Length of list
// Sorts list into ascending order
// Precondition:
// length <= MAX_LENGTH
// && list[0..length-1] are assigned
// Postcondition:
// list contains the same values as list@entry, rearranged
// into ascending order
{
ItemType temp; // Temporary variable
int passCount; // Loop control variable |
|
|
|
|
|
|
|
|
Figure 12-4
Exchanging the Contents of Two Variables, x and y |
|
|
|
|
|