Question: #include using namespace std; string ltrim(const string &); string rtrim(const string &); class node{ // DO NOT EDIT public: int val; node *left; node *right;

#include
using namespace std;
string ltrim(const string &);
string rtrim(const string &);
class node{
// DO NOT EDIT
public:
int val;
node *left;
node *right;
// constructor
node(int v=0, node *L=NULL, node *R=NULL){
val = v;
left = L;
right = R;
}
};
class binary_tree{
public:
node *head;
// constructor
binary_tree(node *_head=NULL){
head = _head;
}
void printLeft(){
// YOUR CODE HERE
}
void printRight(){
// YOUR CODE HERE
}
void countNodes(){
// YOUR CODE HERE
}
};
void testcase0(){
node n6(8);
node n5(6);
node n4(7);
node n3(5);
node n2(3, &n5 , &n6);
node n1(0, &n3 , &n4);
node n0(9, &n1 , &n2);
binary_tree T(&n0);
T.printLeft();
T.printRight();
T.countNodes();
}
void testcase1(){
node n3(5);
node n1(0, &n3 , NULL);
node n0(9, &n1, NULL);
binary_tree T(&n0);
T.printLeft();
T.printRight();
T.countNodes();
}
void testcase2(){
node n0(9);
binary_tree T(&n0);
T.printLeft();
T.printRight();
T.countNodes();
}
void testcase3(){
binary_tree T;
T.printLeft();
T.printRight();
T.countNodes();
}
void test_function(int option) {
switch (option) {
case 0: testcase0(); break;
case 1: testcase1(); break;
case 2: testcase2(); break;
case 3: testcase3(); break;
}
}
int main()
{
string option_temp;
getline(cin, option_temp);
int option = stoi(ltrim(rtrim(option_temp)));
test_function(option);
return 0;
}
string ltrim(const string &str) {
string s(str);
s.erase(
s.begin(),
find_if(s.begin(), s.end(), not1(ptr_fun
);
return s;
}
string rtrim(const string &str) {
string s(str);
s.erase(
find_if(s.rbegin(), s.rend(), not1(ptr_fun
s.end()
);
return s;
}
1. Binary Trees A "Binary Tree" is a bit like a linked list, but instead of the nodes being in a line (where each node points to next), the nodes have TWO pointers, left and right. Each node can have two "child" nodes, and each of those can have two and so on. In this lab, I have created and populated a binary tree for you. You are asked to [a] print the value of the left-most node in the tree [b] print the value of the right-most node in the tree [c] print the number of nodes in the tree (which most easily done with recursion) Study the code I have written and think carefully before you start coding
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
