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

This is all done in c++ (can only use <iostream>) do not use any other libraries

ID: 3757592 • Letter: T

Question

This is all done in c++ (can only use <iostream>) do not use any other libraries

// USE THE BELOW FUNCTION Do NOT ALTER

// Check if a tree contained the value "value" given the head node in the tree. // will have return false; for the base case.
bool ContainsRecursive(const BinaryTreeNode* tree_node, int value)

THE ".h" file is given below;

struct BinaryTreeNode {
int data;
BinaryTreeNode* left_child;
BinaryTreeNode* right_child;
};

class BinaryTree {
public:
BinaryTree();
int Size();
bool Contains(int value);
bool Insert(int value);
bool Remove(int value);
void Clear();

std::string ToString();

BinaryTreeNode* head;
};

Explanation / Answer

we can find the value in a BST using recursion.

C++ implementation of the above code:

bool contains(int key){
Node* p =root;
while((p!=NULL)&&(p->data!=key)){
if(key< p->data)p=p->left;
else p=p->right;
}
return p;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote