//  File: main3.C
//
//  Testing the BSTree class.

#include <stdio.h>
#include <stdlib.h>
#include "bstree.h"

main() {
   BSTree *Tptr, *result ;
   int x, r ;
   char c ;
   data *stuff_ptr ;

   Tptr = new BSTree ;
   Tptr->Insert(5) ;
   Tptr->Insert(2) ;
   Tptr->Insert(3) ;
   Tptr->Insert(8) ;
   Tptr->Insert(6) ;
   Tptr->Insert(9) ;
   Tptr->Insert(4) ;
   Tptr->Insert(1) ;

   // Dump
   printf("\nInorder Walk\n") ;
   Tptr->Inorder() ;
   printf("\n") ;


   // Search & Delete nodes
   printf("\nEdit tree:\n") ;
   while(1) {
      printf("Integer to search & delete: ") ;
      r = scanf("%d", &x) ;
      fflush(stdin) ;
      if (r != 1) break ;

      result = Tptr->Search(x) ;

      if (result == NULL) {
         printf("Not found\n") ;
      } else {
         printf("Deleting ") ;
         result->RootPrint() ;
         printf("...\n") ;
         result->RemoveRoot() ;

         printf("New Tree\n") ;
         Tptr->Inorder() ;
         printf("\n") ;
      }
   }

   // Dump again
   printf("\nInorder Walk\n") ;
   Tptr->Inorder() ;
   printf("\n") ;
}
