CASE STUDY
568
try
{
generateLists(firstFile, firstList);
generateLists(secondFile, secondList);
}
catch(ClassNotFoundException except)
{
System.out.println("problems reading in objects");
}
// Set up for processing first list
firstList.resetList();
firstEntry = firstList.getNextItem();
firstCount = 1 ;
firstLimit = firstList.length();
moreData1 = firstCount <= firstLimit;
// Set up for processing second list
secondList.resetList();
secondEntry = secondList.getNextItem();
secondCount = 1 ;
secondLimit = secondList.length();
moreData2 = secondCount <= secondLimit;
resultList = newSortedList( 200 ); // Instantiate combined list
// Merge loop
while(moreData1 && moreData2)
{
compareResult = firstEntry.knowName().compareTo(secondEntry.knowName());
if(compareResult < 0 ) // firstEntry comes first
{
resultList.insert(firstEntry);
if(firstCount == firstLimit)
moreData1 = false;
else
{
firstEntry = firstList.getNextItem();
firstCount++;
}
}
else if(compareResult > 0 ) // secondEntry comes first
{
resultList.insert(secondEntry);
if(secondCount == secondLimit)
moreData2 = false;