rendered paste body#include <iostream>
#include <ostream>
#include <fstream>
#include "BinarySearchTree.h"
using namespace std;
void printMenu();
void printTabs(int n);
int main()
{
char choice = '0';
string filename;
cout << " Binary Search Tree Balancing and Drawing " << endl;
BinarySearchTree *root = NULL;
ifstream infile;
ofstream ofile;
int k, count;
while(choice != '5')
{
printMenu();
cout << endl << "Choice ? ";
cin >> choice;
switch(choice)
{
case '1' : cout << "Please enter name of data file " << endl;
cin >> filename;
infile.open(filename.c_str());
delete root;
root = NULL;
k=0;
count=0;
while(infile >> k)
{
root->insert(k,root,0);
}
infile.close();
root->setInOrderPos(root,count);
break;
case '2' : root->draw(root,true);
root->serialiseInOrder(root);
//cout << root->inOrder[0][0] << endl;
break;
case '3' : root->balance(root);
break;
case '4' : cout << "Please enter name of output file " << endl;
cin >> filename;
ofile.open(filename.c_str());
root->serialisePreOrder(root);
for(int i = 0; i < root->getSize(root); i++)
{
ofile << root->nextPreOrder()[0] << endl;
}
ofile.close();
break;
case '5' : delete root;
return 0;
}
cout << endl <<endl;
}
return 0;
}
void printMenu()
{
cout << "\t\tMenu " << endl;
cout << " 1. Create new binary search tree " << endl;
cout << " 2. Draw tree " << endl;
cout << " 3. Balance tree" << endl;
cout << " 4. Save tree" << endl;
cout << " 5. Quit" <<endl;
}