//  File: main2.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 & Edit tree
   printf("\nEdit tree:\n") ;
   while(1) {
      printf("Integer to search: ") ;
      r = scanf("%d", &x) ;
      fflush(stdin) ;
      if (r != 1) break ;

      result = Tptr->Search(x) ;

      if (result == NULL) {
         printf("Not found\n") ;
      } else {
         printf("Found: ") ;
         result->RootPrint() ;
         printf("\n") ;

         printf("New value for stuff: ") ;
         r = scanf("%c", &c) ;
         fflush(stdin) ;
         if (r == 0) c = 'a' ;
         stuff_ptr = result->RootDataPtr() ;
         *stuff_ptr = c ;
      }
   }

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