// Tree_LRP.h (c) 2009 walter_wabe@yahoo.com #ifdef English_dox /// \file Tree_LRP.h /// \brief Left-Right-Process iterator. /// \author Walter Wabe Acuña /// \author Adolfo Di Mare /// \date 2009 /// #endif #ifdef Spanish_dox /// \file Tree_LRP.h /// \brief Iterador Izquierda-Derecha-Proceso. /// \author Walter Wabe Acuña /// \author Adolfo Di Mare /// \date 2009 /// #endif #ifndef Tree_LRP_h #define Tree_LRP_h #ifdef English_dox /// Doxygen English documentation. #define English_dox "Doxygen English documentation" /// \def English_dox ///< Marks English documentation blocks. /// \def Tree_LRP_h ///< Avoids multiple inclusion. #endif #ifdef Spanish_dox /// Documentaci¢n en espa¤ol. #define Spanish_dox "Documentaci¢n Doxygen en espa¤ol" /// \def Spanish_dox ///< Macro usado para que Doxygen genere documentación. /// \def Tree_LRP_h ///< Evita la inclusión múltiple. #endif #include #include "Tree_L.h" #include #ifdef English_dox /// Left-Right-Process iterator. #endif #ifdef Spanish_dox /// Iterador Izquierda-Derecha-Proceso. #endif /** \dontinclude test_iterJava.cpp \skipline test::Tree_LRP() \until }} \see test_iterJava::test_Tree_LRP() \see make_a_o(TL::Tree & T) \dontinclude test_iterJava.cpp \skipline T = a \until +--k */ template class Tree_LRP { std::list< TL::Tree > m_Q; ///< std::queue<>. public: /// \c init(). Tree_LRP( const TL::Tree& T = TL::Tree() ) : m_Q() { set(T); } void set( const TL::Tree& T ); ///< \c Iterator::set(). bool hasNext() const; ///< \c Iterator::hasNext(). const TL::Tree next(); ///< \c Iterator::next(). }; template void Tree_LRP::set( const TL::Tree& T ) { m_Q.clear(); // erase whatever was left if ( T.Empty() ) { return; } TL::Tree Child = T.Root(); while ( !Child.Leftmost().Empty() ) { Child = Child.Leftmost(); } while ( !Child.Empty() ) { m_Q.push_back(Child); // std::cout << Child.Data(); if ( !Child.Right_Sibling().Empty() ) { Child = Child.Right_Sibling(); while ( !Child.Leftmost().Empty() ) { Child = Child.Leftmost(); } } else { while ( !Child.Father().Empty() && ( Child==Child.Father().Right_Sibling() ) ) { Child = Child.Father(); } Child = Child.Father(); } } } /* Indicates if the iterator have a next element */ template bool Tree_LRP::hasNext() const { return ( ! m_Q.empty() ); } /* Moves the iterator to it`s next element */ template const TL::Tree Tree_LRP::next() { TL::Tree first = m_Q.front(); m_Q.pop_front(); return first; } #endif // Tree_LRP_h // EOF: Tree_LRP.h