Data Structures and Algorithms in C/C++ 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): 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): a)int count_leaves(BiTree *tree); Returns the number of leaf nodes in the tree. b) int count_non_leaves(BiTree *tree); Returns the number of non-leaf nodes in the tree. c) int get_height(BiTree *tree); Returns the height of the tree.
Data Structures and
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):
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):
a)int count_leaves(BiTree *tree);
Returns the number of leaf nodes in the tree.
b) int count_non_leaves(BiTree *tree);
Returns the number of non-leaf nodes in the tree.
c) int get_height(BiTree *tree);
Returns the height of the tree.
d) 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) 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) 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) 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.
h) Make sure source code is well-commented, consistently formatted, uses no magic numbers/values, follows programming best-practices, and is ANSI-compliant.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images