Code:
/*
2. Ordered List
Description: Program that will combine to lists of data and put them in a sorted order.
File: main.cxx
Programmer: ****
E-mail: ****
Compiler: g++
Last modified: 3/29/05
*/
using namespace std;
#include <iostream>
#include <string>
#include <fstream>
int main()
{
string namesOne, // Used to temporarily store a name from the first file
namesTwo, // Used to temporarily store a name from the second file
temp; // Used to swap the two variables
ifstream inNames1, // Used to input the names from the first file
inNames2; // Used to input the names from the second file
ofstream outNames; // Used to output names to a file
inNames1.open("/Users/****/Documents/School/Rutgers/CS/P4_Luebcke_HOME/merge/names1.data");
inNames2.open("/Users/****/Documents/School/Rutgers/CS/P4_Luebcke_HOME/merge/names2.data");
outNames.open("/Users/****/Documents/School/Rutgers/CS/P4_Luebcke_HOME/merge/names.data");
inNames1 >> namesOne;
inNames2 >> namesTwo;
while(!inNames1 || !inNames2)
{
if(namesOne < namesTwo || !inNames2.eof())
{
outNames << namesOne << endl;
inNames1 >> namesOne;
}
else if(namesTwo < namesOne || !inNames1.eof())
{
outNames << namesTwo << endl;
inNames2 >> namesTwo;
temp = namesTwo;
namesTwo = namesOne;
namesOne = temp;
}
}
inNames1.close();
inNames2.close();
outNames.close();
return 0;
}