< previous page page_812 next page >

Page 812
Merge (In: list1, list2; Out: mergedList)
Set index1 = 0
Set index2 = 0
Set index3 = 0
WHILE neither list1[index1] nor list2[index2] is the sentinel record
  Process components, using index3 to index mergedList
Append any records left over

Write (In: masterList; Inout: masterFile)
Set index = 0
DO
   Write masterList[index].lastName,  
         masterList[index].firstName,  ,
         masterList[index].phone.areaCode,  ,
         masterList[index]. phone. phoneNumber to masterFile
   Increment index
WHILE masterList[index-1 ] isn't the sentinel record

Process Components (In: list1, list2; Inout: mergedList, index1, index2, index3)                    Level 2
IF list1 [index1 .ListName < list2[index2].lastName alphabetically
   Set mergedList[index3] = list1[index1]
   Increment index1
ELSE IF list1[index1].lastName > list2[index2].lastName alphabetically
   Set merged List[index3] = list2[index2]
   Increment index2
ELSE
   Set mergedList[index3] = list1[index1]
   Increment index1
   Increment index2   // Ignore duplicate record in list2
Increment index3

Because Process Components is fairly simple, we include it as part of the Merge function in the program.

 
< previous page page_812 next page >