最近看了本Java版的数据结构 迭代器在原来看的书上没有..现在做出了前序、中序的感觉就是非递归拟栈来实现后序遍历迭代器... 但是没思路搞不出来...希望大家给点思路哈!先谢谢了

解决方案 »

  1.   


     void Postorder(BinaryNode <T> * t)
     {  Stack <StkNode<T>>s(10);
         StkNode<T> Cnode;
         BinaryNode<T> * p = t;
         for(  ;  ;  )
         {  1)while (p!=NULL)
                { Cnode.ptr = p;   Cnode.tag = 0;  s.push(Cnode);
                    p = p->Left;
                }
             2)Cnode = s.pop( );   p = Cnode.ptr;
             3)while ( Cnode.tag = = 1)
                    {  cout << p->element;
                        if ( !s.IsEmpty( ))
                           { Cnode = s.pop( );   p = Cnode.ptr;  }
                        else  return;
                    }
             4)Cnode.tag = 1;  s.push(Cnode);    p = p->Right;
         }//for
     }