Q5 30 Points Linked Data Structures • Assume that you have a TreeNode class. (See code attached for reference.) . Cla
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Q5 30 Points Linked Data Structures • Assume that you have a TreeNode class. (See code attached for reference.) . Cla
Q5 30 Points Linked Data Structures • Assume that you have a TreeNode<T> class. (See code attached for reference.) . Class TreeList<T> below implements a binary tree using TreeNode<T> objects. • You need to write code for the TreeList<T> class insertAfter method. . The insertAfter method creates a new TreeNode<T> object to encapsulate the provided element of type T. . This new node should become the right child of refNode, and count should be updated, too 1. If refNode's right child is null, then the new node can take that position. 2. Otherwise, move refNode's right child to the new node, and then make the new node to be refNode 's right child Because a TreeNode<T> object has a parent reference, you must update each node's parent - if the node's parent changes. Image reference for node insertion concept: ● a)
Image reference for node insertion concept: public class TreeList<T> { Fill in the appropriate part of the code below: 3 a) m. b)
Fill in the appropriate part of the code below: public class TreeList<T> { private TreeNode<T> root; private int count; public TreeList() { count = 0; root = null; } public void insertAfter (T element, TreeNode<T> refNode) { // write your code here // Below there is space to submit an image, if you wish Enter your answer here } } // end class TreeList<T>