
Tree Traversal:
Tree traversal is a method of visit all the nodes of the tree and also display their data. All the nodes are connect via link which means edge. So the edge is used to visit all the nodes in the tree. Tree traversal is classified into three orders. They are:
- Inorder traversal
- Preorder traversal
- Postorder traversal
Inorder traversal - In this method, the left subtree is visited first after that the root node and finally right subtree. In tree traversal every node may represent a subtree itself.
Preorder traversal - In this method, the root is visited first after that the left subtree node and finally right subtree node.
Postorder traversal - In this method, the left subtree node is visited first after that the right subtree node and finally root node is visited.
“displayTree” method:
- The “displayTree” method will display the left subtree and right subtree recursively.
- In the pane the line is added to connect the two nodes. The “displayTree” method first adds the line to the pane then it will add the circle into the pane. So the circle will be painted on top of the lines.

Want to see the full answer?
Check out a sample textbook solution
Chapter 25 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- New Perspectives on HTML5, CSS3, and JavaScriptComputer ScienceISBN:9781305503922Author:Patrick M. CareyPublisher:Cengage LearningC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- COMPREHENSIVE MICROSOFT OFFICE 365 EXCEComputer ScienceISBN:9780357392676Author:FREUND, StevenPublisher:CENGAGE LSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage



