Question
Please help on 7.13 LAB: BST validity checker. I've been struggling with figuring out how to code BTSChecker.h. I would really appreciate the help. Must
Please help on 7.13 LAB: BST validity checker. I've been struggling with figuring out how to code BTSChecker.h. I would really appreciate the help. Must be coded in C++. Only the files shown below are to be used.
TESTS FOR THE CODE
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
main.cpp
#include
int main(int argc, char *argv[]) { // Get user input string userInput; getline(cin, userInput); // Parse into a binary ree Node* userRoot = Node::Parse(userInput); if (userRoot) { Node* badNode = BSTChecker::CheckBSTValidity(userRoot); if (badNode) { cout key)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Node.h
#ifndef NODE_H #define NODE_H
#include
class Node { private: static std::string RemoveLeadingWhitespace(std::string str) { int i = 0; while (i
// Counts the number of nodes in this tree virtual int Count() { int leftCount = 0; if (left) { leftCount = left->Count(); } int rightCount = 0; if (right) { rightCount = right->Count(); } return 1 + leftCount + rightCount; } static void DeleteTree(Node* root) { if (root) { DeleteTree(root->left); DeleteTree(root->right); delete root; } } // Inserts the new node into the tree. virtual void Insert(Node* node) { Node* currentNode = this; while (currentNode) { if (node->key key) { if (currentNode->left) { currentNode = currentNode->left; } else { currentNode->left = node; currentNode = nullptr; } } else { if (currentNode->right) { currentNode = currentNode->right; } else { currentNode->right = node; currentNode = nullptr; } } } } virtual void InsertAll(const std::vector // "Split" on comma int i1 = commaIndices[0]; int i2 = commaIndices[1]; std::string piece1 = treeString.substr(0, i1); std::string piece2 = treeString.substr(i1 + 1, i2 - i1 - 1); std::string piece3 = treeString.substr(i2 + 1); // Make the node with just the key Node* nodeToReturn = new Node(stoi(piece1)); // Recursively parse children nodeToReturn->left = Node::Parse(piece2); nodeToReturn->right = Node::Parse(piece3); return nodeToReturn; } }; #endif ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ BTSChecker.h (Code that must be corrected) #ifndef BSTCHECKER_H #define BSTCHECKER_H // Your code here (include additional header files, if needed) #include "Node.h" class BSTChecker { public: static Node* CheckBSTValidity(Node* rootNode) { // Your code here (remove the placeholder line below) return rootNode; } }; #endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started