I did something wrong here, I suspect its in the insert function, but I can't seem to fix it, am I doing something wrong? I need to do the insert function nonrecursively and the rest recursively
edit: now I'm 100% sure that it is the insert function that is crashing it.
#ifndef BST_H
#define BST_H
#include <string>
#include <iostream>
usingnamespace std;
template<class T>
class Node
{
public:
Node(){}
Node(T theData, Node* theRLink, Node* theLLink)
: data(theData), rlink(theRLink), llink(theLLink){}
Node* getRLink( ) const { return rlink; }
Node* getLLink( ) const { return llink; }
T getData( ) const { return data; }
void setRLink(Node *theRLink) { rlink = theRLink; }
void setLLink(Node *theLLink) { llink = theLLink; }
void setData(const T& theData) { data = theData; }
private:
T data;
Node *rlink, *llink;
};
template<class T>
class BST
{
public:
BST();
//Default constructor
~BST();
//Destructor
void destroyTree();
//Deallocates the memory space occupied by the BST
//Function: insert
//Inserts a given item in the BST (non-recursive)
//Your code here...
void insert(const T&);
//Inserts a given item in the BST (non-recursive)
void inorderTraversal() const;
//Prints nodes of the BT in the inorder sequence
int treeHeight() const;
//Returns the height of the BST
int totalNodes() const;
//Determines the number of nodes in the BST
private:
Node<T> *root; //Pointer to the root
void destroy(Node<T> *p);
//Destroy the BST to which p points
//Function: inorder
//Prints the inorder traversal of the BT to which p points
//Your code here...
void inorder(Node<T> *p) const;
//Function height
//Returns the height of the tree
//Your code here...
int height(Node<T> *p) const;
//Function nodeCount
//Returns the number of nodes in the BST to which p points
//Your code here...
int nodeCount(Node<T> *p) const;
};
#endif