Question: ERRORS facing: Invalid tree with right child linking to ancestor Test feedback: CheckBSTValidity ( ) returned a node that is not the BST rule -
ERRORS facing:
Invalid tree with right child linking to ancestor
Test feedback:
CheckBSTValidity returned a node that is not the BST ruleviolating node. The node with either the left or right child pointing to an ancestor must be returned.
Invalid tree with left child linking to ancestor
Test feedback:
CheckBSTValidity returned a node that is not the BST ruleviolating node.
Code:
#ifndef BSTCHECKERH
#define BSTCHECKERH
#include "Node.h
class BSTChecker
public:
static Node CheckBSTValidityNode root
return CheckBSTValidityRecursiveroot nullptr, nullptr;
private:
static Node CheckBSTValidityRecursiveNode node, Node minNode, Node maxNode
if node nullptr
return nullptr;
if minNode nullptr && nodekey minNodekey
return node;
if maxNode nullptr && nodekey maxNodekey
return node;
if nodeleft nullptr && nodeleft minNode nodeleft maxNode
return node;
if noderight nullptr && noderight minNode noderight maxNode
return node;
Node leftNode CheckBSTValidityRecursivenodeleft, minNode, node;
if leftNode nullptr
return leftNode;
Node rightNode CheckBSTValidityRecursivenoderight, node, maxNode;
if rightNode nullptr
return rightNode;
return nullptr;
;
#endif
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
