Adobe Reader w Window Help 21/6 84.1%- Tools Fill & Sign Com Part 1: Insert node
ID: 3704113 • Letter: A
Question
Adobe Reader w Window Help 21/6 84.1%- Tools Fill & Sign Com Part 1: Insert nodes into a tree We provided a file BinaryTree java that defines a dlass for a binary tree and some methods The method insertNode()inserts a node in the leftmost available free spot. That is, if the method is called in the following sequence: insertNode(58), insertNode(2), insertNode(34), insertNode (19), insertNode (6). then the tree will look Ike 50 34 19 And, if we call insertNode(22), the tree will look like: 50 34 Notice that the breadth-first traversal order of the resulting tree is the order in which nodes were inserted. Implement this method using the fields in the constructor. Notice that there is a Linkedlist called nodes ThatNeedChildren. This List should contain the TreeNodes who are missing 1 or 2 children. Your insert method will use nodesThatNeedChi ldren to know which TreeNode to add a child to. For example, in the first tree above, nodes ThatNeedChildren- TreeNodel341,TreeNode( 19),TreeNode(6)1 and in the second tree, nodes ThatNeedchildren - [TreeNode(34),TreeNode(19),TreeNode(61,TreeNode(2211.Explanation / Answer
public void insert(Node nodeIn, int dataIn){ if (nodeIn == null) { nodeIn = new Node(null, null, dataIn); } else { if (dataInRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.