#include 
#include 
#include 
#include 
#include "class3.h"

main()
{
 char nameofinputfile[80];
 char nameofoutputfile[80];

//get the name of input and output file
 cout << "Enter the name of the input file:" << endl;
 cin >> nameofinputfile;
 cout << "Enter the name of the output file:" << endl;
 cin >> nameofoutputfile;

//Open the files
 ifstream infile(nameofinputfile, ios::in);
 if (!infile) {
   cerr << "File could not be opened" << endl;
   exit(1);
 }//end if

 ofstream outfile(nameofoutputfile, ios::out);
 if (!outfile) {
   cerr << "File could not be opened" << endl;
   exit(1);
 }//end if

 char a;
 SearchTree T;
 string word;
 pageentry p;

 while (infile>>a) {
   readline(infile, word, p);
   updatetree(T,word,p);
 }

 InOrder Itr = T;
 for ( Itr.First(); +Itr; ++Itr) {
   const indexentry& thisindex=Itr();
   thisindex.print(outfile)  ;
   delete thisindex.pagenumbers;
   delete thisindex.name.str;
 }
  
 return 0;
}//end main