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 root;

// the queue of TreeNodes in the tree that have 0 or 1 children private final List> nodesThatNeedChildren;

// 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!