// sl-4-DHBW-Inf2
#include <cstdlib>
#include "suchbaum.h"
#include <iostream>
using namespace std;

int main(void) {
  cout << "... a small program introducing binary search trees ..." << endl;
  bstPtr tree = NULL;
  int zahl;
  cout << "Erster Wert (positiv=einfuegen, negativ=loeschen, 0=Abbruch): ";
  cin >> zahl;
  while (zahl) {
    if (zahl>0) {
      bstInsert(tree,zahl);
      cout << zahl << "eingefuegt" << endl;
      cout << "Preorder : "; preorder(tree); cout << endl;
      cout << "Inorder  : "; inorder(tree); cout << endl;
      cout << "Postorder: "; postorder(tree); cout << endl;      
    } else {
      bstDelete(tree,-zahl);
      cout << zahl << "geloescht" << endl;
      cout << "Preorder : "; preorder(tree); cout << endl;
      cout << "Inorder  : "; inorder(tree); cout << endl;
      cout << "Postorder: "; postorder(tree); cout << endl;      
    }
    cout << "Nexter Wert: ";
    cin >> zahl;
  }

//  cout << "Und noch ein Beispiel für optimale Suchbäume:" << endl;

//  const int elemcount=9;
//  int elems[elemcount]={23,26,31,41,53,58,59,93,97};
//  double probs[elemcount]={0.10,0.16,0.25,0.20,0.10,0.03,0.02,0.08,0.06};

//  bstPtr ob=optBST(elems,probs,elemcount);

//  cout << "Preorder des Lösungsbaums: "; preorder(ob); cout << endl;
//  cout << "Inorder des Lösungsbaums: "; inorder(ob); cout << endl;
//  cout << "Postorder des Lösungsbaums: "; postorder(ob); cout << endl;

  system("Pause");
  return EXIT_SUCCESS;
}
