CPSC 220 Fall 2003
Program 2: A Binary Tree Class

Write a binary tree interface called BinaryTreeADT with the following methods: Then write a class BinaryTree that implements the BinaryTreeADT. Be sure to include the three constructors we discussed in class: In the BinaryTree class, use a queue to construct the iterators; you may use the LinkedQueue class if you wish, which implements the QueueADT class in the text. (To use the Linked Queue class you'll need the LinearNode and LinkedIterator classes as well.) Note that the QueueADT has an iterator() method, so once you get all the elements on the queue in the correct order, you can just return the queue's iterator.

You'll need to write a BTNode class as well to support the linked implementation.

Testing your BinaryTree class

File BTTest.class contains a program that creates the following tree, and uses its four iterators to print preorder, inorder, postorder and levelorder traversals:
                         35
                        /  \
                       25  30
                      /  \
                     15   20
                    /  \
                   5   10
It also lets the user search for various values in the tree, prints the total number of nodes in the tree, and performs some remove operations.

You may copy this file and use it initially to test your BinaryTree class. (Be sure that you name your BinaryTree methods exactly as given above.) However, when you think your BinaryTree class is correct, write your own test class MyBTTest that constructs the tree below and uses its iterators to print the traversals:

                         A
                          \
                           B
                          / \
                         C   D
                        /
                       E
                      / \
                     F   G

Documentation

Include the usual progam header (file name, your name, description of program), plus a header for each method describing its parameters and return value, if any, and its function. Also document any potentially unclear portions of code.

What to Turn In

Turn in hard copy of your BinaryTreeADT.java, BinaryTree.java, BTNode.java, and MyBTTest.java classes. Also tar your directory and e-mail it to bloss@roanoke.edu with cpsc220 prog2 in the subject.