AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
aud.BinaryTreeTraversal< T >.PostorderIterator Class Reference

postorder iterator for BinaryTree More...

+ Inheritance diagram for aud.BinaryTreeTraversal< T >.PostorderIterator:
+ Collaboration diagram for aud.BinaryTreeTraversal< T >.PostorderIterator:

Public Member Functions

boolean hasNext ()
 
BinaryTree< T > next ()
 
- Public Member Functions inherited from aud.BinaryTreeTraversal< T >.RecursiveTraversalIterator
boolean hasNext ()
 
void remove ()
 
- Public Member Functions inherited from aud.BinarySearchTree.Iterator< BinaryTree< T > >
boolean hasNext ()
 
Cursor next ()
 
void remove ()
 not implemented More...
 

Detailed Description

postorder iterator for BinaryTree

Definition at line 125 of file BinaryTreeTraversal.java.

Member Function Documentation

◆ hasNext()

boolean aud.BinaryTreeTraversal< T >.PostorderIterator.hasNext ( )

Reimplemented from aud.BinaryTreeTraversal< T >.RecursiveTraversalIterator.

Definition at line 164 of file BinaryTreeTraversal.java.

164 {
165 assert(stack_.is_empty()==state_.is_empty()); // additional check
166 return super.hasNext();
167 }
boolean is_empty()
Is stack empty?
Definition: Stack.java:14

◆ next()

BinaryTree< T > aud.BinaryTreeTraversal< T >.PostorderIterator.next ( )

Definition at line 169 of file BinaryTreeTraversal.java.

169 {
170 int state;
171 while ((state=state_.pop())!=OUTPUT) {
172 if (state==LEFT) {
173 // stack_.top() remains
174 state_.push(RIGHT);
175
176 descendLeft();
177 }
178 else {
179 // stack_.top() remains
180 state_.push(OUTPUT);
181
182 BinaryTree<T> node=stack_.top();
183 if (node.getRight()!=null) {
184 stack_.push(node.getRight());
185 state_.push(LEFT);
186 }
187 }
188 }
189 return stack_.pop(); // state == OUTPUT
190 }
void push(T x)
Push x onto stack.
Definition: Stack.java:31
T pop()
Pop element from stack.
Definition: Stack.java:23

The documentation for this class was generated from the following file: