Iteradores Java para C++:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Amigas 'defines' Páginas
Tree_BF.h
Ir a la documentación de este archivo.
1 // Tree_BF.h (c) 2009 adolfo@di-mare.com
2 
3 #ifdef English_dox
4 /// \file Tree_BF.h
5 /// \brief Breadth first tree iterator.
6 /// \author Adolfo Di Mare <adolfo@di-mare.com>
7 /// \date 2009
8 /// - Why English names??? ==> http://www.di-mare.com/adolfo/binder/c01.htm#sc04
9 #endif
10 #ifdef Spanish_dox
11 /// \file Tree_BF.h
12 /// \brief Iterador por niveles para el árbol.
13 /// \author Adolfo Di Mare <adolfo@di-mare.com>
14 /// \date 2009
15 /// - Why English names??? ==> http://www.di-mare.com/adolfo/binder/c01.htm#sc04
16 #endif
17 
18 #ifndef Tree_BF_h
19 #define Tree_BF_h
20 
21 #ifdef English_dox
22  /// Doxygen English documentation.
23  #define English_dox "Doxygen English documentation"
24  /// \def English_dox ///< Marks English documentation blocks.
25  /// \def Tree_BF_h ///< Avoids multiple inclusion.
26 #endif
27 #ifdef Spanish_dox
28  /// Documentaci¢n en espa¤ol.
29  #define Spanish_dox "Documentaci¢n Doxygen en espa¤ol"
30  /// \def Spanish_dox ///< Macro usado para que Doxygen genere documentación.
31  /// \def Tree_BF_h ///< Evita la inclusiún múltiple.
32 #endif
33 
34 #include <list>
35 #include "Tree_L.h"
36 
37 #ifdef English_dox
38 /// Breadth first tree iterator.
39 #endif
40 #ifdef Spanish_dox
41 /// Iterador por niveles para el árbol.
42 #endif
43 /**
44  \dontinclude test_iterJava.cpp
45  \skipline test::Tree_BF()
46  \until }}
47  \see test_iterJava::test_Tree_BF()
48 
49  \see make_a_o(TL::Tree<char> & T)
50  \dontinclude test_iterJava.cpp
51  \skipline T = a
52  \until +--k
53 */
54 template <typename E>
55 class Tree_BF {
56  std::list< TL::Tree<E> > m_Q; ///< std::queue<>.
57 public:
58  /// \c init().
59  Tree_BF( const TL::Tree<E>& T = TL::Tree<E>() )
60  : m_Q() { set(T); }
61  void set( const TL::Tree<E>& T ); ///< \c Iterator::set().
62 
63  bool hasNext() const; ///< \c Iterator::hasNext().
64  const TL::Tree<E> next(); ///< \c Iterator::next().
65 };
66 
67 template <typename E>
68 void Tree_BF<E>::set( const TL::Tree<E>& T ) {
69  m_Q.clear(); // erase whatever was left
70  if ( T.Empty() ) {
71  return;
72  }
73  m_Q.push_back( T.Root() );
74  typename std::list< TL::Tree<E> >::const_iterator iQ;
75  iQ = m_Q.begin();
76  while ( iQ != m_Q.end() ) {
77  TL::Tree<E> Child = iQ->Leftmost();
78  while ( ! Child.Empty() ) {
79  m_Q.push_back( Child );
80  Child = Child.Right_Sibling();
81  }
82  ++iQ;
83  }
84  // Algorithm: push_back() children until no one is left.
85  // - This implementation relies on the queue m_Q being able to
86  // push_back() without affecting iteraror iQ.
87 }
88 
89 template <typename E>
90 bool Tree_BF<E>::hasNext() const {
91  return ( ! m_Q.empty() );
92 }
93 
94 template <typename E>
96  TL::Tree<E> first = m_Q.front();
97  m_Q.pop_front();
98  return first;
99 }
100 
101 #endif // Tree_BF_h
102 // EOF: Tree_BF.h
std::list< TL::Tree< E > > m_Q
std::queue&lt;&gt;.
Definition: Tree_BF.h:56
const TL::Tree< E > next()
Iterator::next().
Definition: Tree_BF.h:95
void set(const TL::Tree< E > &T)
Iterator::set().
Definition: Tree_BF.h:68
Tree Right_Sibling() const
Obtiene el hermano no vacío siguiente, que está hacia la derecha.
Definition: Tree_L.h:521
Iterador por niveles para el árbol.
Definition: Tree_BF.h:55
Tree Leftmost() const
Obtiene el hijo más izquierdo del árbol.
Definition: Tree_L.h:698
bool hasNext() const
Iterator::hasNext().
Definition: Tree_BF.h:90
Declaraciones y definiciones para la clase Tree.
bool Empty() const
Retorna &quot;true&quot; si el sub-árbol está vacío.
Definition: Tree_L.h:91
Los métodos para trabajar con árboles regresan &quot;referencias&quot; que son sub-árboles. ...
Definition: Tree_L.h:25
Tree Root() const
Raíz del sub-árbol.
Definition: Tree_L.h:154