Hi there! I have a question with regards to the Binary Search Tree Implemetation in C++. Here is the question below
Implement a simple (non-templated) BST which stores integers. Provide the following operations: Insert, Remove, inOrder traversal, preOrder traversal, postOrder traversal.
Use recursive routines for dealing with the tree.
Processing a node simply involves printing out the contents of the node, which in this case is the integer being stored in the node.
Data should come from test files. The main program should open the data file and insert into the tree and demonstrate other tree operations.
The point of this exercise is to demonstrate that you understand the BST. There is no need to go overboard with it and put in operations not asked for.
I have only created the Header file so far. Could anyone please take a look and advise if I am heading in the right direction?
using namespace std;
#ifndef BSTNODE_H
#define BSTNODE_H
class BSTNode
{
private:
//Defines the 'node' structure
struct tree_node
{
tree_node *left; // left subtree has smaller elements
tree_node *right; // right subtree has larger elements
int m_data;
};
//root * r;
public:
//The Constructor
BSTNode();
//The Destructor
~BSTNode();
//Inserts a value into a BST, public function
void insert(const m_data & d);
//Removes a value from a BST, public function
void remove(const m_data & d);
//isEmpty function, public function
bool isEmpty();
BSTNode getData();
void inOrder(const m_data & d);
void preOrder(const m_data & d);
void postOrder(const m_data & d);
};
#endif
Next I have to create the BSTNode.cpp file. Appreciate your response via mail to [email protected] Thanks in advance.