Java Reference
In-Depth Information
΢΢΢Exercise P16.14. Change the BinarySearchTree.print method
to print the tree as a tree shape. You can print the tree sideways. Extra
credit if you instead display the tree with the root node centered on the
top.
761
762
΢ Exercise P16.15. Implement methods that use preorder and postorder
traversal to print the elements in a binary search tree.
΢΢΢Exercise P16.16. In the BinarySearchTree class, modify the
remove method so that a node with two children is replaced by the
largest child of the left subtree.
΢΢Exercise P16.17. Suppose an interface Visitor has a single method
void visit(Object obj)
Supply methods
void inOrder(Visitor v)
void preOrder(Visitor v)
void postOrder(Visitor v)
to the BinarySearchTree class. These methods should visit the tree
nodes in the specified traversal order and apply the visit method to the
data of the visited node.
΢΢Exercise P16.18. Apply Exercise P16.17 to compute the average value of
the elements in a binary search tree filled with Integer objects. That is,
supply an object of an appropriate class that implements the Visitor
interface.
΢΢Exercise P16.19. Modify the implementation of the MinHeap class so
that the parent and child index positions and elements are computed
directly, without calling helper methods.
΢΢΢Exercise P16.20. Modify the implementation of the MinHeap class so
that the 0 element of the array is not wasted.
Search WWH ::




Custom Search