Mozilla/mozilla/js/js2/java/PostorderNodeIterator.java
rogerl%netscape.com 382f120d73 Changes for try/catch handling
git-svn-id: svn://10.0.0.236/trunk@27801 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-16 02:54:56 +00:00

57 lines
1.1 KiB
Java

import java.util.Stack;
class PostorderNodeIterator {
PostorderNodeIterator(Node n)
{
stack = new Stack();
while (n.first != null) {
stack.push(n);
n = n.first;
}
start = n;
}
Node peekParent()
{
if (stack.isEmpty())
return null;
else
return (Node)stack.peek();
}
void pop()
{
if (stack.isEmpty())
current = null;
else
current = (Node)stack.pop();
}
Node nextNode()
{
if (current == null)
return current = start;
if (stack.isEmpty())
return current = null;
else {
current = current.next;
if (current != null) {
while (current.first != null) {
stack.push(current);
current = current.first;
}
}
else
current = (Node)stack.pop();
}
return current;
}
Node start;
Node current;
Stack stack;
}