< previous page page_1013 next page >

Page 1013
        }
        else
            GetRecord(inFile, aPerson);
    }
}

//******************************************************************

void RecordList::SelSort()

// Sorts ptrList so that the pointed-to structs are in
// ascending order of last name

// Precondition:
//     ptrList[0..length-1] point to valid PersonnelData structs
// Postcondition:
//     ptrList contains the same values as ptrList@entry, rearranged
//     so that consecutive elements of ptrList point to structs in
//     ascending order of last name

{
   PersonPtr tempPtr;       // 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):
         //     ptrList[0..passCount-1] point to structs in
         //     ascending order of last name
         //  && 0 <= passCount <= length - 1

      minIndex = passCount;

      // Find the index of the pointer to the alphabetically first
      // last name remaining in ptrList[passCount..length-1]

      for (placeCount = passCount + 1; placeCount < length;
                                                       placeCount++)
            // Invariant (prior to test):
            //    ptrList[minIndex]->lastName is less than or equal
            //    to all ptrList[passCount]->lastName through
            //    ptrList[placeCount-1]->lastName
            // && placeCount <= length

 
< previous page page_1013 next page >