Question: I need some help for public class PostorderIterator implements Iterator public class BinaryTree { //Implements a Binary Tree of Strings private class Node { private
I need some help for public class PostorderIterator implements Iterator
public class BinaryTree {
//Implements a Binary Tree of Strings
private class Node {
private Node left;
private String data;
private Node right;
private Node parent; // reference to the parent node
// the parent is null for the root node
private Node(Node L, String d, Node r, Node p) {
left = L;
data = d;
right = r;
parent = p;
}
}
private Node root;
public BinaryTree() {
// create an empty tree
root = null;
}
public BinaryTree(String d) {
// create a tree with a single node
root = new Node(null, d, null, root);
}
public class PostorderIterator implements Iterator {
//An iterator that returns data in the tree in a post order pattern
//This implementation must use a stack and must not use the parent pointer
//You must use Javas stack class
public PostorderIterator() {
}
public boolean hasNext() {
}
public String next() {
}
public void remove() {
//optional method not implemented
}
}
public Iterator postorder() {
// return a new post order iterator object
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
