Question
WRITE the iterator and Treeheight recursively Public interface Tree> extends Iterable { int treeheight(); int nodedepth(); } public class BinaryTre> implements Tree { private TreeNode
WRITE the iterator and Treeheight recursively
Public interface Tree> extends Iterable
{
int treeheight();
int nodedepth();
}
public class BinaryTre> implements Tree {
private TreeNode root;
private int size;
@Override
public int size() {
return size;
}
@Override
public boolean isEmpty() {
return size == 0;
}
@Override
public int treeheight() {
return 0;
}
@Override
public int treeHeight() {
return 0;
}
@Override
public Iterator iterator() {
return null;
}
private class TreeNode {
private T data;
private TreeNode left;
private TreeNode right;
public TreeNode(T data) {
this.data = data;
}
@Override
public String toString() {
String left = this.left != null ? this.left.data.toString() : "null";
String right = this.right != null ? this.right.data.toString() : "null";
return left + " " + right;-->
}
}
}
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