The program of Figs. 21.15 and 21.16 illustrated three recursive methods of traversing a binary treeinorder, preorder
Question:
The program of Figs. 21.15 and 21.16 illustrated three recursive methods of traversing a binary tree—inorder, preorder and postorder traversals. This exercise presents the level-order traversal of a binary tree, in which the node values are printed level by level, starting at the root-node level. The nodes on each level are printed from left to right. The level-order traversal is not a recursive algorithm. It uses a queue object to control the output of the nodes. The algorithm is shown in Fig. 21.22. Write method levelOrder to perform a level-order traversal of a binary tree object. Modify the program of Figs. 21.15 and 21.16 to use this method.
Fig. 21.22
Fig. 21.15
Fig. 21.16
Step by Step Answer:
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates