56 return wasSuccessful();
64 std::list<long> Lfwd, Lbck, L;
65 assertTrue( Lfwd.empty() && L.empty() );
70 while ( itFwd.hasNext() && itBck.hasNext() ) {
71 Lfwd.push_back( itFwd.next() );
72 Lbck.push_back( itBck.next() );
77 { std::list<long> Lcp, L;
81 assertTrue( ! iter.hasNext() );
86 assertTrue( iter.hasNext() );
87 assertTrue( iter.next() == 1 );
88 assertTrue( ! iter.hasNext() );
93 assertTrue( iter.hasNext() );
94 assertTrue( iter.next() == 1 );
95 assertTrue( iter.hasNext() );
96 assertTrue( iter.next() == 2 );
97 assertTrue( ! iter.hasNext() );
99 assertTrue( iter.next() == 1 );
101 assertTrue( iter.next() == 2 );
102 assertTrue( ! iter.hasNext() );
109 while ( iter.hasNext() ) {
110 Lcp.push_back( iter.next() );
120 #define dim(V) ( sizeof(V)/sizeof(*V) )
122 int VEC[] = { 1, 2, 3, 4, 5 };
125 L.push_back( iter.
next() );
135 #warning Macro [const_error] already defined
140 std::list<long> Lcp, L;
141 assertTrue( Lcp.empty() );
144 while ( iter.hasNext() ) {
145 Lcp.push_back( iter.next() );
150 assertTrue( L == Lcp );
152 assertTrue( IT == iter && !( IT.
hasNext() ) && !( IT != iter ) );
156 std::list<long> Lcp, L;
157 assertTrue( Lcp.empty() );
158 L = longlist(
"( 1 2 3 4 5 )" );
159 const std::list<long> & L_const = L;
161 while ( iter.hasNext() ) {
162 Lcp.push_back( iter.next() );
164 assertTrue( L == Lcp );
166 assertTrue( IT == iter && !( IT.
hasNext() ) && !( IT != iter ) );
180 Iter iter( L.begin(),L.end() );
181 while ( iter.hasNext() ) {
187 template <
typename C>
205 typedef std::list<long>::const_iterator IterFwd;
206 typedef std::reverse_iterator<IterFwd> IterBck;
211 while ( itFwd.hasNext() && itBck.hasNext() ) {
212 if ( itFwd.next() != itBck.next() ) {
213 assertTrue(
"palindrome error" &&
false );
216 assertTrue( !itFwd.hasNext() && !itBck.hasNext() );
220 typedef std::list<long>::const_iterator Iter;
225 if ( itFwd.
next() != itBck.
next() ) {
226 assertTrue(
"palindrome error" &&
false );
237 typedef std::list<long>::const_iterator Iter;
240 assertTrue( itFwd.
next() == 1 );
247 assertTrue( itBck.
next() == 5 );
258 typedef typename C::const_iterator Iter;
263 if ( itFwd.
next() != itBck.
next() ) {
270 template <
typename C>
272 typedef typename C::const_iterator IterFwd;
273 typedef typename std::reverse_iterator<IterFwd> IterBck;
278 while ( itFwd.hasNext() && itBck.hasNext() ) {
279 if ( itFwd.next() != itBck.next() ) {
283 return ( !itFwd.hasNext() && !itBck.hasNext() );
334 bool palindromo(
const std::list< std::string >& L);
336 assertTrue(
palindromo( str2list(
"[ 1 2 3 2 1 ]") ) );
337 assertFalse(
palindromo( str2list(
"[ 1 2 3 2 0 ]") ) );
338 assertTrue(
palindromo( str2list(
"[ r a d a r ]") ) );
339 assertFalse(
palindromo( str2list(
"[ M A J E M ]") ) );
361 while ( iter.hasNext() ) {
362 switch (trngl++ % 3) {
364 long & l = iter.
next(); l++;
368 long * p = & iter.next(); (*p)++;
384 while ( itFwd.hasNext() && itBck.hasNext() ) {
386 L.push_back( itFwd.next() );
387 L.push_back( itBck.next() );
388 if ( itFwd.current() == itBck.current() ) {
394 assertTrue( L.size() != 7 );
395 assertTrue( n == 3 );
396 assertTrue( itFwd.next() == 3 );
397 assertTrue( itBck.next() == 3 );
408 while ( iter.hasNext() ) {
409 i++; assertTrue( i == iter.
next() );
413 while ( iter.hasNext() ) {
414 i++; assertTrue( i == iter.
next() );
416 assertTrue( L1.empty() );
425 i--; assertTrue( i == iter.
next() );
429 i--; assertTrue( i == iter.
next() );
437 std::list<long> L, Lcp;
441 iter123.
set( L.begin(), L.end() );
444 assertTrue( i == iter123.
next() );
450 assertTrue( i == iter45.
next() );
457 std::list<long> L, Lcp;
461 iter123.
set( L.begin(), L.end() );
464 assertTrue( i == iter123.
next() );
471 assertTrue( i == iter45.
next() );
477 assertTrue( L.empty() );
487 while ( iter.hasNext() ) {
488 assertTrue( ! L.empty() );
489 long *pL = & iter.
next(); i++;
490 assertTrue( i == *pL );
493 assertTrue( L.empty() );
520 assertTrue( L ==
"abcdefghijklmno" &&
"Tree_BF" );
526 assertTrue( ! iter.
hasNext() &&
"Tree_BF" );
529 assertTrue( iter.
hasNext() &&
"Tree_BF" );
530 assertTrue(
'A' == iter.
next().Data() &&
"Tree_BF" );
531 assertTrue( ! iter.
hasNext() &&
"Tree_BF" );
538 T.
Child(1).Change_Child(2,
'2');
539 T.
Child(1).Child(2).Change_Child(3,
'3');
540 iter.
set(T); L.clear();
545 assertTrue( L ==
"A123" &&
"Tree_BF" );
561 assertTrue( L ==
"0123456" &&
"Tree_BF" );
579 assertTrue( L ==
"FBGADICEH" &&
"Tree_BF" );
599 assertTrue( L ==
"ABCDEFGHIJKLMNO" &&
"Tree_BF" );
614 assertTrue( L ==
"abfghcdeijlmnok" &&
"Tree_PLR" );
620 assertTrue( ! iter.
hasNext() &&
"Tree_PLR" );
623 assertTrue( iter.
hasNext() &&
"Tree_PLR" );
624 assertTrue(
'A' == iter.
next().Data() &&
"Tree_PLR" );
625 assertTrue( ! iter.
hasNext() &&
"Tree_PLR" );
641 assertTrue( L ==
"0134256" &&
"Tree_PLR" );
659 assertTrue( L ==
"FBACEDGIH" &&
"Tree_PLR" );
679 assertTrue( L ==
"ABDHIEJKCFLMGNO" &&
"Tree_PLR" );
694 assertTrue( L ==
"fbghacdieljnmok" &&
"Tree_LPR" );
700 assertTrue( ! iter.
hasNext() &&
"Tree_LPR" );
703 assertTrue( iter.
hasNext() &&
"Tree_LPR" );
704 assertTrue(
'A' == iter.
next().Data() &&
"Tree_LPR" );
705 assertTrue( ! iter.
hasNext() &&
"Tree_LPR" );
721 assertTrue( L ==
"3140526" &&
"Tree_LPR" );
722 assertTrue( L !=
"314526" &&
"Tree_LPR [T.Root() missing]" );
741 assertTrue( L ==
"CAEBDFGHI" &&
"Tree_LPR" );
742 assertTrue( L !=
"CAEDHI" &&
"Tree_LPR [ BFG missing ]" );
743 assertTrue( L !=
"CAEBDFGHIH" &&
"Tree_LPR [Extra H]" );
744 assertTrue( L !=
"CAEBDFG" &&
"Tree_LPR [ HI missing ]" );
764 assertTrue( L ==
"HDIBJEKALFMCNGO" &&
"Tree_LPR" );
765 assertTrue( L !=
"HDIJEKLFMNGO" &&
"Tree_LPR [ BAC missing ]" );
780 assertTrue( L ==
"fghbcdilnomjkea" &&
"Tree_LRP" );
786 assertTrue( ! iter.
hasNext() &&
"Tree_LRP" );
789 assertTrue( iter.
hasNext() &&
"Tree_LRP" );
790 assertTrue(
'A' == iter.
next().Data() &&
"Tree_LRP" );
791 assertTrue( ! iter.
hasNext() &&
"Tree_LRP" );
807 assertTrue( L ==
"3415620" &&
"Tree_LRP" );
825 assertTrue( L ==
"CEADBHIGF" &&
"Tree_LRP [Wabe]" );
826 assertTrue( L !=
"CEADBHIF" &&
"Tree_LRP [ G missing ]" );
846 assertTrue( L ==
"HIDJKEBLMFNOGCA" &&
"Tree_LRP [Wabe]" );
847 assertTrue( L !=
"HIDJKEBLMFNOGA" &&
"Tree_LRP [ C missing ]" );
1076 Random iter( 15, 271828 );
1078 std::cout << iter.
next() << std::endl;
1088 template <
class Collection>
1092 ITER iter( C.begin(), C.end() );
1093 while ( iter.hasNext() ) {
1094 std::cout << iter.
next();
1102 #include "Tree_Ex.h"
1110 std::cout << tester.report();
1114 std::cout <<
"useIterator( L ); ==> ";
1116 assert( L.empty() );
An iterator over a collection.
int main()
Test ==> main() ==> iterJava().
std::list< long > makeList_long(const char *V)
Left-Right-Process iterator.
const TL::Tree< E > next()
Iterator::next().
void set(Iter first, Iter end)
Resets the iterator to traverse from first up to end.
Left-Process-Right iterator.
void test_examplePtr()
Test ==> iterJava<> ==> examplePtr().
void generateRandom()
Example usage of Java iterators as generators.
const TL::Tree< E > next()
Iterator::next().
Test ==> iterJava<>.
void set(const TL::Tree< E > &T)
Iterator::set().
const TL::Tree< E > next()
Iterator::next().
void test_palindrome()
Test ==> iterJava<> ==> palindrome().
void test_const_example()
Test ==> iterJava<> ==> const_example().
bool isBackward() const
Returns true if the iteration goes in reverse (backwards).
bool palindromo(const std::list< std::string > &L)
Regresa true si al recorrer el contenedor "L" hacia adelante se obtiene el mismo resultado que al rec...
void make_A_H(TL::Tree< char > &T)
T = ( F ( B ( A ( C E ) D ) ) G ( I ( H ) ) ).
void useIterator(Collection &C)
Example usage of the iterJava<> iterator class.
Tree Graft(unsigned n, Tree &o)
Injerta "o" para que sea el "n"-ésimo hijo de "*this".
void make_0_6(TL::Tree< char > &T)
T = ( 0 ( 1 ( 3 4 ) 2 ( 5 6 ) ) ).
void test_erase()
Test ==> iterJava<> ==> erase().
void test_palindromo()
Test ==> iterJava<> ==> palindrome().
void test_set_CCC()
Test ==> iterJava<> ==> set(CCC).
void make_A_O(TL::Tree< char > &T)
T = ( A ( B ( D ( H I) E ( J K ) ) C ( F ( L M ) G ( N O ) ) ) ).
bool hasNext() const
Iterator::hasNext().
std::iterator_traits< Iter >::reference next()
Returns the next element in the iteration.
bool run()
Test ==> iterJava<> ==> run().
Random(unsigned n=1, long seed=3145159)
Iterator::init()
void const_compile_error(std::list< long > &L)
Implementation to show that const_iterator cannot be used to erase values.
bool isReverse() const
Returns true if the iteration goes in reverse (backwards).
void test_Tree_PLR()
Test ==> iterJava<> ==> Tree_PLR().
void test_example()
Test ==> iterJava<> ==> example().
bool hasNext() const
Iterator::hasNext().
void set(const TL::Tree< E > &T)
Iterator::set().
C++ encapsulation of a generator as a Java iterator.
void make_a_o(TL::Tree< char > &T)
T = ( a ( b ( f g h ) c d e ( i j ( l m ( n o ) ) k ) ).
Left-Right-Process iterator.
void test_setReverse()
Test ==> iterJava<> ==> setReverse().
void Erase()
Elimina el árbol y sus descendientes.
bool isPalindrome(const C &CCC)
Returns true when CCC is a palindrome.
void test_Tree_LPR()
Test ==> iterJava<> ==> Tree_LPR().
Breadth first tree iterator.
bool hasNext() const
Iterator::hasNext().
void setReverse()
Sets the iterator to go reverse (backwards).
bool hasNext() const
Iterator::hastNext()
bool isForward() const
Returns true if the iteration is natural, from first to last.
Breadth first tree iterator.
Los métodos para trabajar con árboles regresan "referencias" que son sub-árboles. ...
void set(const TL::Tree< E > &T)
Iterator::set().
const long & next()
Iterator::next()
bool hasNext() const
Iterator::hasNext().
bool hasNext() const
Returns true if the iteration has more elements.
void test_next()
Test ==> iterJava<> ==> next().
void set(const TL::Tree< E > &T)
Iterator::set().
Process-Left-Right iterator.
Tree Child(unsigned n) const
Acceso al "n"-ésimo hijo.
void test_isPalindrome()
Test ==> iterJava<> ==> isPalindrome().
Left-Process-Right iterator.
const TL::Tree< E > next()
Iterator::next().
void test_assign()
Test ==> iterJava<> ==> assign(CCC).
void test_Tree_LRP()
Test ==> iterJava<> ==> Tree_LRP().
void test_Tree_BF()
Test ==> iterJava<> ==> Tree_BF().
Tree Change_Child(unsigned n, const value_type &d)
Sustituye por "d" el valor almacenado en el hijo número "n" del árbol.
Process-Left-Right iterator.