A binary search tree of integers is constructed of nodes defined using the follo
ID: 3903728 • Letter: A
Question
A binary search tree of integers is constructed of nodes defined using the following C++ struct:
struct Node {
int value; Node* left; Node* right;
};
Given a binary search tree of integers, write a C++ function between that takes the root node pointer of a tree, an int lower bound lower, an int upper bound upper, and a reference to a std::set<int>, and adds into the set all integers in the tree that are between the lower and upper bounds, inclusive.
For instance, using the example tree depicted here, a call to between(root, 36, 89, result) would populate the result set with 40, 55, 60, 70, 80.
void between(Node* root, int lower, int upper, std::set<int>& result) {
Explanation / Answer
void between(Node* root, int lower, int upper, std::set& result) { if(root == NULL){ return; } if(root->value >= lower && root->value value); } between(root->left, lower, upper, result) between(root->right, lower, upper, result) }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.