Tree Methods inorderTraversal, preorderTraversal and postorderTraversal

Methods inorderTraversal, preorderTraversal and postorderTraversal call Tree helper methods inorderHelper (lines 88–96), preorderHelper (lines 71–79) and postorderHelper (lines 105–113), respectively, to traverse the tree and print the node values. The helper methods in class Tree enable you to start a traversal without having to pass the root node to the method. Reference root is an implementation detail that a programmer should not be able to access. Methods inorderTraversal, preorderTraversal and postorderTraversal simply take the private root reference and pass it to the appropriate helper method to initiate a traversal of the tree. The base case for each helper method ...

Get Java™ How To Program (Early Objects), Tenth 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.