IMPORTANT. Submit the .java files that you write for this lab through OWL by 11:55pm on Friday, April 3.
getData()
,
getLeft()
, getRight()
, setData(newData)
, setLeft(newLeft)
, and setRight(newRight)
.
LinkedBinaryTree.java
:
getDataRoot
, returns the data item stored in the root of the tree
isEmpty
, returns true if the tree is empty and false otherwise
size(BinaryTreeNode< T > r)
, returns the number of nodes in the subtree with root
r
. This method must be recursive. Please try to implement this method on your own.
If you need help read this hint.
contains(BinaryTreeNode< T > r, T targetElement
, returns true if the given targetElement
is stored in any of the nodes in the subtree with root r
.
This method must be recursive. Please try to implement this method on your own.
If you need help read this hint.
iteratorPreOrder
, preorder
, iteratorPostOrder
, and postorder
. The first two methods construct an iterator containing the information of the nodes of a tree stored in preorder; the last two methods construct an iterator containing the information on postorder.TestBinaryTree.java
to learn how to use an iterator.
Hint: Model your code for the above methods on the methods iteratorInOrder
and inorder
of class LinkedBinaryTree
. The main change that you need to make is where the node is visited in preorder and postorder.
iteratorLevelOrder
, returns a iterator containing the data stored in the nodes of a tree in level order. This method is not recursive. Use class LinkedQueue
as the auxiliary data structure needed to perform a level order traversal of the tree. Read the lecture notes on tree traversal. Note that in the
queue you will store tree nodes, so what should be the value of the generic type for the declaration of the queue? (LinkedQueue< ??? > queue;
)
TestBinaryTree
. All 6 test must pass; if your program fails any tests use the debugger to find the errors and fix them.