Question: Node.java public class Node { private E info; private Node parent; private Node left; private Node right; public Node(E val) { info=val; parent =null; left

Node.java public class Node{ private E info; private Node parent; private Node left; private Node right; public Node(E val) { info=val; parent =null; left =null; right = null; } public E getInfo() { return this.info; } public void setInfo(E val) { this.info = val; } public void setLeft(Node v ) { this.left =v; } public void setRight(Node v) { this.right=v; } public void setParent(Node v) { this.parent=v; } public Node getParent() { return this.parent; } public Node getLeft() { return this.left; } public Node getRight() { return this.right; } }
BinaryTree.java
import java.util.ArrayList; import java.util.LinkedList;
public class BinaryTree
Node
public BinaryTree(E val) { root = new Node
public void setLeftBT(Node
p.setLeft(c); c.setParent(p); numNodes++; }
public void setRightBT(Node
p.setRight(c); c.setParent(p); numNodes++; }
public boolean isLeaf(Node
public boolean isSubRoot(Node
if (p.getLeft() != null || p.getRight() != null) { return true; } return false; }
public boolean isMainRoot(Node
if (p.getParent() == null) { return true; } return false; }
public boolean deleteLeaf(Node
public LinkedList public static void main(String[] args) { BinaryTree bt.postOrder(bt.root); System.out.println(" Is Leaf Node : " + bt.isLeaf(n2)); System.out.println(" Is Sub Root : " + bt.isSubRoot(n4)); System.out.println(" Is Main Root : " + bt.isMainRoot(bt.root)); //Node deletion if (bt.isLeaf(n2)) { bt.deleteLeaf(n2); } else { System.out.println("Not Leaf Node"); } //copy System.out.println("After Cloning : " + bt.cloneToLL(bt.preOrder(bt.root))); } public void buildBT() { BinaryTree } public ArrayList preOrder(Node public void postOrder(Node public void inOrder(Node if (t == null) { return; } inOrder(t.getLeft()); System.out.println(t.getInfo()); inOrder(t.getRight()); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
