TreeTraversal PostOrder NonRecursive

Note: not checked for correctness

template< typename NodePointer, typename Functor > Functor visit_postorder_nonrecursive( NodePointer root, Functor visit ) { NodePointer p (root); bool down (true); while (p) { if ( down ) { for (p->left; p = p->left ) {} down = false; visit(p->data); }        else { if ( p == p->parent->left ) { if ( !p->parent->right ) { visit(p->parent->data); p = p->parent->parent; }                else { p = p->parent->right; down = true; }            }             else { assert( p == p->parent->right ); visit(p->data); p = p->parent; }        }     }     return visit; }