|
|
|
|
|
|
|
void TimeCardList::SelSort()
// Postcondition:
// list contains the same values as list@entry, rearranged
// into ascending order of employee ID
{
TimeCard temp; // Used for swapping
int passCount; // Loop control variable
int placeCount; // Loop control variable
int minIndex; // Index of minimum so far
for (passCount = 0; passCount < length - 1; passCount++)
{
// Invariant (prior to test):
// list[0..passCount-1] are in ascending
// order of employee ID
// && 0 <= passCount <= length - 1
minIndex = passCount;
// Find the index of the smallest component
// in list [passCount..length-1]
for (placeCount = passCount + 1; placeCount < length;
placeCount++)
// Invariant (prior to test):
// ID number in list[minIndex] is less than or equal
// to ID numbers in list[passCount..placeCount-1]
// && placeCount <= length
if (list[placeCount].IDPart() < list[minIndex].IDPart())
minIndex = placeCount;
// Swap list[minIndex] and list[passCount]
temp = list[minIndex];
list[minIndex] = list[passCount];
list[passCount] = temp;
}
}
//******************************************************************
|
|
|
|
|
|