正在加载图片...
前序遍历的迭代器 遍历二叉树: Tree Iterator:前序的实现。 template <class Type> class Preorder: public TreeIterator Type> public Preorder( const Binary Tree< Type >&R) Preorder(i void first id operator ++( void Preorder nlr() protected: Stack< const BinaryNode <Type >*>s template class Type> Preorder<Type>: Preorder( const Binary Tree <Type >&R) TreeIterator<Type>(R) S Push( T. Getroot()) template class Type> void Preorder <Type>:: First() s Make Empty () if( T. Getroot())s Push( T. Getroot()) operator ++( //堆栈清空。若二叉树T非空,则根结点进栈,并得到当前结点。前序遍历的迭代器 • 遍历二叉树:Tree Iterator:前序的实现。 template <class Type> class Preorder : public TreeIterator < Type > { public: Preorder( const BinaryTree < Type > & R ); ~Preorder( ) { } void First( ); void operator ++ ( ); void Preorder_NLR ( ); protected: Stack < const BinaryNode <Type > * > s; }; template <class Type> Preorder<Type> :: Preorder( const BinaryTree <Type> & R ) : TreeIterator<Type > ( R ) { s.Push( T.Getroot( ) ); } template <class Type> void Preorder <Type> :: First ( ) { s.MakeEmpty ( ); if ( T.Getroot( ) ) s.Push( T.Getroot( ) ); operator ++( ); } //堆栈清空。若二叉树T非空,则根结点进栈,并得到当前结点
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有