Question: BSTNode.h #ifndef BSTNODE _ H #define BSTNODE _ H #include class BSTNode { private: virtual BSTNode * Search ( int searchKey ) { BSTNode *
BSTNode.h
#ifndef BSTNODEH
#define BSTNODEH
#include
class BSTNode
private:
virtual BSTNode Searchint searchKey
BSTNode currentNode this;
while currentNode
Return currentNode if the key matches
if currentNodekey searchKey
return currentNode;
Branch left or right
else if searchKey currentNodekey
currentNode currentNodeleft;
else
currentNode currentNoderight;
Key not found
return nullptr;
public:
int key;
BSTNode left;
BSTNode right;
BSTNodeint nodeKey, BSTNode leftChild nullptr, BSTNode
rightChild nullptr
key nodeKey;
left leftChild;
right rightChild;
virtual ~BSTNode
virtual bool Containsint key
return Searchkey nullptr;
static void DeleteTreeBSTNode node
if node
DeleteTreenodeleft;
DeleteTreenoderight;
delete node;
Inserts a new key into the subtree rooted at this node, provided the key
doesn't already exist
virtual bool InsertKeyint key
Duplicate keys not allowed
if Containskey
return false;
Allocate the new node
InsertNodenew BSTNodekey;
return true;
virtual void InsertKeysconst std::vector& keys
for int key : keys
InsertKeykey;
virtual void InsertNodeBSTNode newNode
BSTNode currentNode this;
while currentNode
if newNodekey currentNodekey
if currentNodeleft
currentNode currentNodeleft;
else
Insert new node as currentNode's left child
currentNodeleft newNode;
currentNode nullptr;
else
if currentNoderight
currentNode currentNoderight;
else
Insert new node as currentNode's right child
currentNoderight newNode;
currentNode nullptr;
;
BSTChecker.h
#ifndef BSTCHECKERH
#define BSTCHECKERH
TODO: Include any needed header files
#include "BSTNode.h
class BSTChecker
public:
TODO: Add any desired utility functions
CheckBSTValidty determines if the tree is a valid BST If so nullptr
is returned. If not, the first in preorder traversal node in violation
of BST requirements is returned. Such a node will be one of the following:
A node in the left subtree of an ancestor with a lesser or equal key
A node in the right subtree of an ancestor with a greater or equal key
A node that is encountered more than once during traversal
static BSTNode CheckBSTValidityBSTNode rootNode
;
#endif
#endif
Test cases in man.cpp
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
