End isEmpty . One, rather inelegant, technique is to isolate the node to be removed from the tree and then add all the elements from its left and right subtrees to the original tree. The details of this require that the element required is first located, marked for removal and held in a local variable to be return ed from the action. To support this the TreeNode class supports a boolean toBeRemoved attribute which is false by default. However, this would cause the numberOfElements data attribute to contain an incorrect value so it is stored before trimming and restored, after being decremented, before the action terminates.
End remove .
Accordingly the BinaryTreeEnumeration constructor extracts all the data from the tree into a Vector and iterates through this Vector in order to traverse the data in the tree. Appendix B. As with the OrderedList class, the BinaryTree class implements the OrderedStructure interface so the same demonstration test harness as was used for the OrderedList in Chapter 14 can be used with this structure, once all occurrences of OrderedList have been replaced with BinaryTree . Send the BinaryTreeDemo.java source code . 15.10 LinkedList s, and BinaryTree s compared .