< previous page page_810 next page >

Page 810
How would we do this process by hand if we had two stacks of index cards? We would probably take the top card from each stack and compare the names. If they were the same, we would put one in a new stack and throw the other one away. If they weren't the same, we would put the card with the name that came first alphabetically in the new stack and take a replacement card from the stack that the card came from. We would repeat this process until one of the stacks of index cards became empty. Then we would move the rest of the other stack to the new one. Of course, the lists might both end at the same time with a duplicate name.
We can employ this same process to solve the problem using two computer lists. Rather than having two stacks of index cards, we have two computer files. Examining the next person's record is the equivalent of take a replacement card from that stack.
Now that we have solved the problem for two files, we can expand the solution to three files. We can merge the first two files and store the result into a temporary list, then merge that list with the records from the third file.
Data Structures: We use a struct type to represent one person's information:
typedef char String15[16];       // Room for 15 characters plus \0
struct PersonRec
{
    String 15  lastName;
    String 15  firstName;
    PhoneType phone;
};
where PhoneType is itself a struct type.
typedef char String8[9];       // Room for 8 characters plus \0
struct PhoneType
{
    int     areaCode;      // Range 100..999
    String8 phoneNumber;
};
Notice that PersonRec is therefore a hierarchical record type.
To store the records from the input files and merge them, we use four onedimensional arrays whose components are of type PersonRec:

 
< previous page page_810 next page >