Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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 #2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions

Question

3. Would you say that effective teamwork saved their lives?

Answered: 1 week ago