IN C 1 Implement a node class for Binary Tree BT Each node s
IN C++
1. Implement a node class for Binary Tree (BT). Each node should record its parent
node, left and right child nodes.
2. Manually construct a BT by following the below figure
3. Implement countLeaf function that computes the # of leaves in the BT.
4. Implement depth function that computes the depth of the BT.
5. Implement levelOrderScan that prints out all nodes’ values in level order.
6. Implement lookup that finds whether a character passed in the lookup function
can be found in the BT or not.
7. Implement size function that computes the number of nodes in the BT.
8. Implement minNode that returns the value (or Node* if you prefer) of the Node
that has minimum value of the BT.
9. Implement path(Node* x) that prints the path from root to x Node. If x is not
available, print empty string.
10. Implement mirror function that will flip B and C nodes. It also flips D and E
nodes.
Solution
3)
4)
5)
/* Function to line by line print level order traversal a tree*/
void printLevelOrder(struct node* root)
{
int h = height(root);
int i;
for (i=1; i<=h; i++)
{
printGivenLevel(root, i);
printf(\"\ \");
}
}
/* Print nodes at a given level */
void printGivenLevel(struct node* root, int level)
{
if (root == NULL)
return;
if (level == 1)
printf(\"%d \", root->data);
else if (level > 1)
{
printGivenLevel(root->left, level-1);
printGivenLevel(root->right, level-1);
}
}
7)

