im pretty new with C++ , I've recently received a project to create my own Binary Search Tree using a Template. The goal is for the Binary Tree to be able to take in any kind of data type. I've created 2 classes , Node(h,cpp) ,Tree(h,cpp) , and a main cpp. for some reason i get all the time acces violation (probaly from of the destructor , it is getting a corrupted value).
... here is my code(its the whole thing so it whould be easier..) . thanks...
template <typename T>
std::ostream& operator<<(std::ostream& output, const Tree<T>& tree)
{
if (!tree.getRoot())
return output;
Node<T> * temp=tree.getRoot();
Tree<T> tempL(temp->getL());
output<<tempL;
output<<temp->getValue();
output<<endl;
Tree<T> tempR(temp->getR());
output<<tempR;
return output;
}
#endif
#include "Tree.h"
void main ()
{
Node<int> *no=new Node<int>(7);
Tree<int> IntTree(no);
IntTree.insert(new Node<int> (5));
IntTree.insert(new Node<int> (0));
IntTree.insert(new Node<int> (4));
IntTree.insert(new Node<int> (5));
IntTree.insert(new Node<int> (12));
IntTree.insert(new Node<int> (7));
IntTree.insert(new Node<int> (1));
IntTree.insert(new Node<int> (14));
IntTree.insert(new Node<int> (7));
IntTree.insert(new Node<int> (51));
if(IntTree.exists(5.1))
cout<<IntTree;
}