< previous page page_1008 next page >

Page 1008
ReadAll (Inout: inFile; Out: outOfMem)
Set outOfMem = FALSE
Set aPerson = new PersonnelData    // Allocate a dynamic struct
Get a record from inFile into
   the struct pointed to by aPerson
WHILE NOT EOF on inFile AND NOT outOfMem
   Set ptrList[length] = aPerson   // Store pointer into array
   Increment length
   Set aPerson = new PersonnelData // Allocate a dynamic struct
   IF aPerson is NULL
      Print warning message
      Set outOfMem = TRUE
   ELSE
      Get a record from inFile into
         the struct pointed to by aPerson

The pseudocode step Get a record from inFile appears twice in ReadAll. This step breaks down into several substeps: read the last name, check for end-of-file, read the first name, and so on. To avoid physically writing down the substeps twice, let's write a separate helper function named GetRecord. In GetRecord's parameter list, aPerson is a pointer to a PersonnelData struct.
GetRecord (Inout: inFile; In: aPerson)
Read aPerson->lastName from inFile
IF EOF on inFile
   Return
Read aPerson->firstName from inFile
Read aPerson->address.street from inFile
Read aPerson->address.city from inFile
Read aPerson->address.state from inFile
Read aPerson->workHistory from inFile
Read aPerson->education from inFile
Read aPerson->payrollData from inFile

The SelSort function is nearly the same as in Chapter 12. The original SelSort finds the minimum value in the list and swaps it with the value in the first place in the list. Then the next smallest value in the list is swapped with the value in the second place. This process continues until all the val-

 
< previous page page_1008 next page >