Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
1) root (lines of code = 7) 11
2) parent (lines of code = 9) 11
3) leftChild (lines of code = 8) 11
4) rotateR (lines of code = 15) 12
5) first (lines of code = 4) 11
6) next (lines of code = 13) 11
7) set (lines of code = 11) 11
8) insert (lines of code = 5) 11
9) delete (lines of code = 8) 11
Total 100
Figure 1: A tree created by parsing the string “((1 2 3) 4 (null 5 (6 7 8)))”. You have to rotate your head
to see it. As the user walks around, the current node is indicated with < .. >.
11. You are write a set of methods for a new class called TreeWalker that extends my IOT ree class. As
such, a TreeWalker object consists of a binary tree that can be inputted and printed in a pretty way.
Your class will will have three additional system invariants.
(a) The tree is displayed on the screen as done in Figure 1.
(b) Exactly one of its nodes is marked as the current node. This acts as a cursor.
(c) The nodes of the tree will be order so that it is a binary search tree.
Each constructor for your class must ensure that it establishes each of these invariants. Each of your
methods must ensure that it maintains them, i.e. if these system invariants are true before it is executed
then they will be true after. Your code does not attempt to maintain it, but the user may wish to
maintain the additional system invariant that the tree is an AVL tree. Your class will provide the tools
for doing this.
I provide the class MainGUI which consists of an event processing loop. It waits for one of the following
commands from the user and then calls the appropriate method from your TreeWalker class. Note how
the system invariants for the class become the loop invariants for this loop.
Each of the methods here takes the current position as the input and returns the new current position.
They do not change the current flag in these nodes and do not reprint the tree. This is done in GUI
with the following lines of code.