What's the algorithm for a PostOrder traversal of a binary tree?
This doesn't seem to be working.
public class POIterator implements Iterator{
private final Deque<BNode> someStack;
BNode position;
public POIterator(BNoderoot){
someStack = new LinkedList<BNode>();
someStack.push(root);
}
public boolean hasNext(){return !someStack.isEmpty();}
public T next(){
position = someStack.pop();
if(position.hasLeftChild()){
someStack.push(position.getLeftNode());
next();}
if(position.hasRightNode()){
someStack.push(position.getRightNode());
next();}
return position.getData();
}
}
Is there something missing from my code. An error/bug perhaps?
It looks like you're new here. If you want to get involved, click one of these buttons!