Question
Bianry Tree Code Used in Java public class BinaryTree { private T data; private BinaryTree parent; private BinaryTree left; private BinaryTree right; public BinaryTree() {
Bianry Tree Code Used in Java
public class BinaryTree
{
private T data;
private BinaryTree
private BinaryTree
private BinaryTree
public BinaryTree()
{
parent = left = right = null;
data = null;
}
public void makeRoot(T data)
{
if (!isEmpty())
{
System.out.println("Can't make root. Already exists");
}
else
this.data = data;
}
public void setData(T data)
{
this.data = data;
}
public void setLeft(BinaryTree
{
left = tree;
}
public void setRight(BinaryTree
{
right = tree;
}
public void setParent(BinaryTree
{
parent = tree;
}
public T getData()
{
return data;
}
public BinaryTree
{
return parent;
}
public BinaryTree
{
return left;
}
public BinaryTree
{
return right;
}
public void attachLeft(BinaryTree
{
if (tree==null) return;
else if (left!=null || tree.getParent()!=null)
{
System.out.println("Can't attach");
return;
}
else
{
tree.setParent(this);
this.setLeft(tree);
}
}
public void attachRight(BinaryTree
{
if (tree==null) return;
else if (right!=null || tree.getParent()!=null)
{
System.out.println("Can't attach");
return;
}
else
{
tree.setParent(this);
this.setRight(tree);
}
}
public BinaryTree
{
if (this.isEmpty()) return null;
BinaryTree
left = null;
if (retLeft!=null) retLeft.setParent(null);
return retLeft;
}
public BinaryTree
{
if (this.isEmpty()) return null;
BinaryTree
right =null;
if (retRight!=null) retRight.setParent(null);
return retRight;
}
public boolean isEmpty()
{
if (data == null)
return true;
else
return false;
}
public void clear()
{
left = right = parent =null;
data = null;
}
public BinaryTree
{
if (parent == null)
return this;
else
{
BinaryTree
while (next.getParent()!=null)
next = next.getParent();
return next;
}
}
public static
{
if (t!=null)
{
System.out.print(t.getData()+"\t");
preorder(t.getLeft());
preorder(t.getRight());
}
}
public static
{
if (t!=null)
{
inorder(t.getLeft());
System.out.print(t.getData() + "\t");
inorder(t.getRight());
}
}
public static
{
if (t!=null)
{
postorder(t.getLeft());
postorder(t.getRight());
System.out.print(t.getData() + "\t");
}
}
}
This is java program and need to put some new methods in the program
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started