#include <iostream>
#include <stdlib.h>
#include <conio.h>
#include "BST.h"

int main(int argc, char *argv[])
{
  BinarySearchTree *bst =  new BinarySearchTree();
  BinarySearchTree *bst1 = new BinarySearchTree();     // creating a BST pointer.
  BinaryNode *bn;
  int number;
  char choice;
  cout << "\n\n \t\t\tEnter command to perform on tree.\n\n";
  cout<<"\n   a -- add a new number ";
  cout<<"\n   h -- print the current height of the BST. ";
  cout<<"\n   d -- delete the number ";
  cout<<"\n   s -- sum all elements of Tree";
  cout<<"\n   c -- To check tree is balance or not ";
  cout<<"\n   e -- To chekc whether two trees are similar or equal ";
  cout<<"\n   q -- quit the program. ";
  
  do{   
        cout<<"\n\n   Enter a character command-- ";cin>>choice;
        
    switch( choice){
                  
         case 'a': // add new recored in the tree
         case 'A':
                   cout<<"\n\nEnter number to insert in tree: ";cin>>number;
                   bn = new BinaryNode(number,NULL,NULL);     
                   bst->insert(*bn);
         break;
         
         case 'h':
         case 'H':
                    bst->height();       // to check the height of tree.
         break;
         
         case 'd':
         case 'D':
                  cout<<"\n\n Enter the number to delete: "; cin>>number;
                  bst->remove(number) ;     // calling remove to delete a node from BST
                 
         break;
         
         case 's':
         case 'S':
                   cout<<"\n Sum of all element of nodes are: "<<bst->sum();
                            
         break;
         
         case 'c':
         case 'C':
                 if(bst->completeTree())
                    cout<<"Tree is balance ";
                 else
                    cout<<"Tree is not balance";
                 
         break;
         
         case 'e':
         case 'E':
         
                 cout<<"\n    First make another tree to compare with other tree \n\n";
                 cout<<"   Enter 1 Add a new number into the second tree  \n\n";
                 cout<<"   Enter 2 to compare two trees  \n\n";
                 cout<<"   Enter q to exit from this second command: \n";
                 do{
                    char cho;
                    cout<<" \n Enter a chatacter command: \n";cin>>cho;
                    
                    if(cho=='q')
                       break;
                    switch(cho){
                        case '1':
                             cout<<"\n Enter number to add in second tree: ";
                             cin>>number;
                             bn = new BinaryNode(number,NULL,NULL);
                             bst1->insert(*bn);
                        break;
                        
                        case '2':
                             if(bst->similarTree(bst, bst1)==true)
                                cout<<"\nBoth Trees are similar"<<endl;
                             else
                                cout<<"\nTrees are not similar"<<endl;
                                                     
                        break;  
                    }
                 }while(true); 
         
         break;
         
         case 'q':
         case 'Q':
            exit(0);
         break;
         
         default:
            
             cout << "\n       Invalid Option or Command Formate , Try again \n" ;
         break;
         }
    }while(1);    
  
  
  system("PAUSE");	
  return 0;
}
