Starting from:
$25

$19

Homework #6


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):

Tree #1





















Tree #2




















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.

1
CSE-40049

    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.

    h) (1 point) Make sure your source code is well-commented, consistently formatted, uses no magic numbers/values, follows programming best-practices, and is ANSI-compliant.

Turn in all source code, program output, diagrams, and answers to questions in a single Word or PDF document.
















2

More products