... each of which is inserted into the binary tree by calling method insertNode (line 17). The program then performs preorder, inorder and postorder traversals (these will be explained shortly) of tree (lines 21, 24 and 27, respectively).

Overview of Class Tree<E>

Class Tree<E> (Fig. 21.15, lines 44–101) requires its type argument to implement interface Comparable, so that each value inserted in the tree can be compared with the existing values to find the insertion point. The class’s private root (line 45) instance variable is a TreeNode<E> reference to the tree’s root node. Tree<E>’s constructor (line 48) initializes root to null to indicate that the tree is empty. The class contains method insertNode (lines 51–58) to insert a new node in the tree ...

Get Java How To Program, Late Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.