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;

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

public class BinaryTree { Node root; int numNodes; public BinaryTree(E val) { root = new Node(val); numNodes=1; } public void setLeftBT(Node p, Node c) { p.setLeft(c); c.setParent(p); numNodes++; } public void setRightBT(Node p, Node c) { p.setRight(c); c.setParent(p); numNodes++; } public static void main(String[] args){ BinaryTree bt = new BinaryTree("cat"); //bt.root = new Node("cat"); Node n1 = new Node("dog"); Node n2 = new Node("rabbit"); // make n1 left child of the root bt.setLeftBT(bt.root, n1); // make n2 right child of the root bt.setRightBT(bt.root,n2); Node n3 = new Node("mouse"); Node n4 = new Node("hamster"); bt.setLeftBT(n1,n3); bt.setRightBT(n2,n4); bt.postOrder(bt.root); } public void buildBT() { BinaryTree bt= new BinaryTree(0); } public void preOrder(Node t){ if (t==null) return; System.out.println(t.getInfo()); preOrder (t.getLeft()); preOrder(t.getRight()); } public void postOrder(Node t) { if (t==null) return; postOrder (t.getLeft()); postOrder(t.getRight()); System.out.println(t.getInfo()); } public void inOrder(Node t) { if (t==null) return; inOrder (t.getLeft()); System.out.println(t.getInfo()); inOrder(t.getRight()); } }

Develop code and add the following methods to the BinaryTree.java class and ensure they work correctly. // returns true if p is leaf and false otherwise public boolean isLeaf(Node p) ( //returns true if p is root and false otherwise. public boolean isRoot(Node p) // if p is a leaf node deletes the node from the tree returning //true, otherwise returns false. public boolean deleteLeaf (Node p) //copies information in the binary tree into a linked list. The //information is the "info" field. Use preorder traversal to get info // Create additional methods or extra declare data structures // if and when needed. public LinkedList cloneTOLL ()

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!