< previous page page_817 next page >

Page 817
    do
    {
        inFile >> list[index].lastName
               >> list[index].firstName
               >> list[index].phone.areaCode
               >> list[index].phone.phoneNumber;
        index++;

            // Invariant:
            //     list[0..index-1] contain the first index
            //     input records
            //  && Sentinel record is not in list[0..index-2]

    } while (strcmp(list[index-1].lastName, SENTINEL) != 0);
}

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

void Merge( /* in */ const PersonRec list1[],       // List to merge
            /* in */ const PersonRec list2[],       // List to merge
            /* out */      PersonRec mergedList[] ) // Resulting
                                                    //   merged list

// Merges list1 and list2 into mergedList

// Precondition:
//     The elements of list1 and list2 are in ascending order
//     of last name, and both contain sentinel records
//  && The size of mergedList is at least as large as the
//     length of list1 plus the length of list2
// Postcondition:
//     mergedList contains the elements of both list1 and list2
//     in ascending order of last name without duplicates
//  && The last element of mergedList is the (only) sentinel record

{
    int index1 = 0;   // Index variable for list1
    int index2 = 0;   // Index variable for list2
    int index3 = 0;   // Index variable for mergedList
    int strRelation;  // Result of comparing two last names

    while (strcmp(list1[index1].lastName, SENTINEL) != 0 &&
           strcmp(list2[index2].lastName, SENTINEL) != 0  )
    {
            // Invariant (prior to test)
            //     mergedList[0..index3-1] contain the elements
            //     of list1[0..index1-1] and list2[0..index2-1]
            //     without duplicates, in ascending order of

 
< previous page page_817 next page >