I'm trying to make this program work with a double threaded BST, instead of a normals Binary Search Tree
I have tried to look at other implementations both double and single to see how they are performed, but it still isn't clicking
BSTNode<Key, E>* BST<Key, E>::inserthelp(BSTNode<Key, E>* root, const Key& k, const E& it) {
if (root == NULL) // Empty tree: create node
return new BSTNode<Key, E>(k, it, NULL, NULL);
if (k < root->key())
root->setLeft(inserthelp(root->left(), k, it));
else root->setRight(inserthelp(root->right(), k, it));
return root; // Return tree with node inserted
Here is what I am working with. This function is meant to be used in another function called insert()
void insert(const Key& k, const E& e) {
root = inserthelp(root, k, e);
nodecount++;
}
I don't understand how to make inserthelp work with a double threaded BST. The inserthelp and insert function a part of a BST class and the following code is part of BSTNode class
class BSTNode : public BinNode<E> {
private:
Key k; // The node's key
E it; // The node's value
BSTNode* lc; // Pointer to left child
BSTNode* rc; // Pointer to right child
bool rightIsThreaded; //Returns true if points to in order successor
bool leftIsThreaded; //Returns true if points to in order predecessor
public:
// Two constructors -- with and without initial values
BSTNode() {
lc = rc = NULL;
}
BSTNode(Key K, E e, BSTNode* l = NULL, BSTNode* r = NULL)
{
k = K; it = e; lc = l; rc = r;
}
~BSTNode() {} // Destructor
// Functions to set and return the value and key
E& element() { return it; }
void setElement(const E& e) { it = e; }
Key& key() { return k; }
void setKey(const Key& K) { k = K; }
// Functions to set and return the children
inline BSTNode* left() const { return lc; }
void setLeft(BinNode<E>* b) { lc = (BSTNode*)b; }
inline BSTNode* right() const { return rc; }
void setRight(BinNode<E>* b) { rc = (BSTNode*)b; }
// Return true if it is a leaf, false otherwise
bool isLeaf() { return (lc == NULL) && (rc == NULL); }
// Set/Get functions to receive value whether it is thread or node pointer
void setLeftThreaded() {
lc = leftIsThreaded;
}
void setRightThreaded() {
rc = rightIsThreaded;
}
bool getLeftThreaded() {
return lc;
}
bool getRightThreaded() {
return rc;
}
The bool functions are meant to return whether that child is threaded or not