Question
In this assignment you are asked to implement a variety of functions that operate on binary trees (the binary tree implementation from the book). You
In this assignment you are asked to implement a variety of functions that operate on binary trees (the binary tree implementation from the book). You will be asked to test these functions on the following two trees (element data type is int):
For parts a through g, implement the given function and demonstrate the function working with the two trees provided earlier in this document:
a) (1 point) int count_leaves(BiTree *tree); Returns the number of leaf nodes in the tree.
b) (1 point) int count_non_leaves(BiTree *tree); Returns the number of non-leaf nodes in the tree.
c) (1 points) int get_height(BiTree *tree); Returns the height of the tree.
d) (1 point) void print_pre_order(BiTree *tree, void (*print)(const void *data))
Prints the elements of the tree to stdout using a pre-order traversal. The print parameter should contain the logic to print the data held in each node in the tree.
e) (1 point) void print_in_order(BiTree *tree, void (*print)(const void *data))
Prints the elements of the tree to stdout using an in-order traversal. The print parameter should contain the logic to print the data held in each node in the tree.
f) (1 point) void print_post_order(BiTree *tree, void (*print)(const void *data))
Prints the elements of the tree to stdout using a post-order traversal. The print parameter should contain the logic to print the data held in each node in the tree.
g) (3 points) void remove_leaves(BiTree *tree) Removes all leaf nodes from the tree.
Use print_pre_order, print_in_order, or print_post_order after calling remove_leaves to show that remove_leaves successfully removed all leaves.
Tree #1 Tree #2Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started