Lab:

Binary tree


Prelab Tasks:

1.      Review what we learned about tree and binary tree.

2.      Read and understand d_tnode.h

3.      Read d_tnodel.h and understand functions: buildTree, depth, deleteTree, clearTree, countLeaf 

Lab Tasks:

1. This lab task will count one child nodes in a tree:

·         Declare and define the function countOneChild in a file named countOneChild.h. The function will counts the number of interior nodes in a binary tree having one child.

·         Write a program in a file named Lab03_01.cpp that will test the countOneChild function for Tree 1. [Hint: mimic buildTree function from "d_tnodel.h" to allocate nodes for Tree 1.]

·         Run your program and print out the outputs.

2.  This lab task will find a maximum value in a binary tree.

·         Declare and define the function max in a file named max.h that will return the maximum value in a tree.

·         Write your program in a file named Lab03_02.cpp to display the maximum value in the integer tree created by the function buildIntTree( ) for Tree 2 

o       Using buildTree function  in d_tnodel.h as a model, implement a function buildIntTree function that builds the integer tree for Tree 2:

o    The tree in this question is binary tree not binary search tree. You need to use  "d_tnode.h" to declare tnode objects.

·         Run your program and print out the outputs

 

What to Turn In

Hand in all source codes (except provided d_tnodel.h and d_tnode.h) and sample outputs to the instructor.