I
I
IBM7012015-03-25 03:00:46
Java
IBM701, 2015-03-25 03:00:46

How to implement a reverse iterator (PostOrder) to traverse a binary tree in Java?

Tell me how to implement a reverse iterator (PostOrder) to traverse a binary tree in Java, without using stack and other collections.
There is a class:

class Node{
    Node left;
    Node right;
    Node parent;
    int val;
}

And interface:
interface CIterator{
    bool hasNext();
    int next();
}

And you need to implement the class:
class PostOrderIterator implements CIterator{
    Node n;
    public PostOrderIterator(Node k){
        n = k;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Pavlov, 2015-03-25
@gurinderu

What type of tree traversal do you generally use?
And why create your own interfaces when there is a ListIterator?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question