Question: I need to use bit or Boolean fields to indicate whether a node pointer is a thread or regular pointer for a double threaded binary

I need to use bit or Boolean fields to indicate whether a node pointer is a thread or regular pointer for a double threaded binary search tree in C++. Not sure how to go about this, so any help would be appreciated. Thanks! Code to be modified is below:

#include "book.h" #include "BinNode.h"

#ifndef BSTNODE_H #define BSTNODE_H

// Simple binary tree node implementation template class BSTNode : public BinNode { 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

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* b) { lc = (BSTNode*)b; } inline BSTNode* right() const { return rc; } void setRight(BinNode* b) { rc = (BSTNode*)b; }

// Return true if it is a leaf, false otherwise bool isLeaf() { return (lc == NULL) && (rc == NULL); } }; #endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!