PostOrder traversal of a binary tree. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

PostOrder traversal of a binary tree.

pylertpylert Posts: 0Member
edited April 2014 in Java

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?

Tagged:
Sign In or Register to comment.