Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a recursive function: Template<typenameT> int checkBST(stnode<T>*t) this f

ID: 3564070 • Letter: W

Question

write a recursive function:

Template<typenameT>

int checkBST(stnode<T>*t)

this function takes a pointer to the root node of a tree and returns:

"1" if the tree satisfies the search tree order property at every node
"0" if it does not

Explanation / Answer

#ifndef BST_H_ #define BST_H_ #include #include #include "btnode.h" using namespace std; /* A class to represent a templated binary search tree. */ template class BST { private: //pointer to the root node in the tree BTNode* root; public: //default constructor to make an empty tree BST(); /* You have to document these 4 functions */ void insert(T value); bool search(const T& value) const; bool search(BTNode* node, const T& value) const; void printInOrder() const; void remove(const T& value); //function to print out a visual representation //of the tree (not just print the tree's values //on a single line) void print() const; private: //recursive helper function for "print()" void print(BTNode* node,int depth) const; }; /* Default constructor to make an empty tree */ template BST::BST() { root = NULL; } template void BST::insert(T value) { BTNode* newNode = new BTNode(value); cout left == NULL && current->right == NULL) break; if(current->right != NULL && current->left != NULL) { if(newNode->data > current->data) current = current->right; else if(newNode->data data) current = current->left; } else if(current->right != NULL && current->left == NULL) { if(newNode->data data) break; else if(newNode->data > current->data) current = current->right; } else if(current->right == NULL && current->left != NULL) { if(newNode->data > current->data) break; else if(newNode->data data) current = current->left; } } if(current->data > newNode->data) { current->left = newNode; /* cout