< previous page page_818 next page >

Page 818
            //     last name
            //  && The sentinel is not in list1[0..index1-1]
            //  && The sentinel is not in list2[0..index2-1]

        strRelation = strcmp(list1[index1].lastName,
                             list2[index2].lastName);
        if (strRelation < 0)
        {
            // Assert: Last name in 1st list is less than in 2nd
            mergedList[index3] = list1[index1];
            index1++;

        }
        else if (strRelation >> 0)
        {
            // Assert: Last name in 1st list is greater than in 2nd
            mergedList[index3] = list2[index2];
            index2++;
        }
        else
        {
            // Assert: Last names are the same in both lists
            mergedList[index3] = list1[index1];
            index1++;
            index2++;
        }
        index3++;
    }
    Append(list1, list2, mergedList, index1, index2, index3);
}

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

void Append(
  /* in */   const PersonRec list1[],        // List being merged
  /* in */   const PersonRec list2[],        // List being merged
  /* inout */      PersonRec mergedList[],   // Resulting list
  /* inout */      int&      index1,         // Index for list1
  /* inout */      int&      index2,         // Index for list2
  /* inout */      int&      index3       )  // Index for mergedList

// Appends remainder of either list1 or list2 to mergedList

// Precondition:
//     Either list1 [index1] contains the sentinel record
//     or list2[index2] contains the sentinel record, or both do
// Postcondition:
//     IF list1[index1@entry] contains the sentinel record

 
< previous page page_818 next page >