private void innerProcessSubTree ( GBSNode p , int initialState , int topIndex ) { boolean done = false ; _topIndex = topIndex ; _endp = p ; _endIndex = _idx ; GBSNode q ; /* Used for tree walking */ int s = initialState ; while ( ! done ) { switch ( s ) { case NodeStack . VISIT_LEFT : s = NodeStack . PROCESS_CURRENT ; q = p . leftChild ( ) ; while ( q != null ) { push ( s , p ) ; p = q ; q = p . leftChild ( ) ; } break ; case NodeStack . PROCESS_CURRENT : s = NodeStack . VISIT_RIGHT ; done = processNode ( p ) ; _endp = p ; /* Last node processed */ _endIndex = _idx ; /* Index to parent of last node processed*/ break ; case NodeStack . VISIT_RIGHT : s = NodeStack . DONE_VISITS ; q = p . rightChild ( ) ; if ( q != null ) { push ( s , p ) ; s = NodeStack . VISIT_LEFT ; p = p . rightChild ( ) ; } break ; case NodeStack . DONE_VISITS : if ( _idx == topIndex ) /* Have finally hit end of sub-tree */ done = true ; else { s = _state [ _cidx ] ; p = _node [ _cidx ] ; pop ( ) ; } break ; default : throw new RuntimeException ( "Help!, s = " + s + "." ) ; // break; } /* switch(s) */ } /* while ( !done ) */ }
Walk through an entire sub - tree invoking processNode on each node .