Question: I need to implement a method in java insertNode() of a binary tree using breadth-first using the fields in the constructor. The method uses the
I need to implement a method in java insertNode() of a binary tree using breadth-first using the fields in the constructor. The method uses the linked list to know which tree node to add a child to.
public class BinaryTree
// the root of the tree private TreeNode
// the queue of TreeNodes in the tree that have 0 or 1 children private final List
// number of TreeNodes in the tree public int size;
public BinaryTree() { root = null; nodesThatNeedChildren = new LinkedList<>(); size = 0; }
/* Insert the element d into the BinaryTree at the "next available location" starting with the left */ public void insertNode(T d)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
