CMPS 1053 - PROGRAM 8 - BINARY SEARCH TREE Spring 2012

advertisement
CMPS 1053 - PROGRAM 8 - BINARY SEARCH TREE
Spring 2012
Due: Friday, May 4 at noon – NO PROGRAMS ACCEPTED LATE!!
Write a main function which calls the functions build, inorder, preorder, postorder. Define a
struct for the tree node. Write a BinaryTree class which contains recursive functions build,
inorder, preorder, postorder and their non-recursive counterparts. The non-recursive
functions must check & print “Tree is empty” if an attempt is made to print an empty tree.
Minimum Assignment:
Your last programming assignment is to build a binary search tree of integers, and recursively
print out the values in inorder, postorder, and preorder form, as follows:
Inorder: 1 2 4 9 .... etc.
Preorder: .......
Postorder: ...........
Additional Assignment for extra credit. You may do either A or B or both.
A: Write a recursive function to determine the height of the tree. Print out the height.
B: Write a recursive function to produce the table as shown below. (A sample is given, you
are to use your tree, of course.)
Inorder Traversal
Node-Data
20
50
67
90
L.Child-Data R.Child-Data
—
—
20
67
—
90
—
—
Make sure that your code is well documented and that your output is also well documented.
No programs will be accepted after noon on Friday, May 4. Turn in what you have on Friday,
whether it works or not.
Use your own small data set for testing. A data file will be provided for final turn in.
Download