//brian jahns
//cs252 1999
//binary search tree .h file

#ifndef BST_H
#define BST_H

#include <iostream.h>
#include <fstream.h>
#include <ctype.h>
#include "Bintree.h"
#include "Word.h"

const int BUFSIZE = 256;

template <class T>
class BST : public BinTree<T> {

friend ifstream& operator >> (ifstream&, BST<T>&);
friend ofstream& operator << (ofstream&, BST<T>&);

public:

BST();
BST(const BST<T>&);
~BST();

bool Insert(const T&);
bool Delete(const T&);
bool Find(const T&) const;


private:

bool FindHelper(const T&, Bnode<T>*) const;
//bool InsertHelper(const T&, Bnode<T>*&);
bool DeleteHelper(Bnode<T>*&, const T&);
bool DeleteItem(Bnode<T>*&);
void FindMinRST(Bnode<T>*&, T&);

};

template <class T>
ofstream& operator << (ofstream& fs, BST<T>& bst)
{
return fs;
}

template <class T>
ifstream& operator >> (ifstream& fs, BST<T>& bst){
char buffer[BUFSIZE];
Str s;
Data d;
int k;
int line = 1;
while(fs.getline(buffer, BUFSIZE)){
//fs.getline(buffer, BUFSIZE);
cerr << buffer << endl;
k = 0;
while (buffer[k] != '\n' && buffer[k] != '\0'){
if (isalpha(buffer[k]))
s = s + buffer[k];
else if (s.length() != 0){
s.downcase();
d.Setword(s);
d.Increment();
d.Addline(line);
bst.Insert(d);
s = "";
}
k++;
}
line++;
}
return fs;
}


#endif