Mercurial > Algorithms__Sedgewick
diff algs4-c++/src/Queue.cpp @ 24:028689700a47
Updated Queue to have a const_iterator too and to support a copy constructor (problem 1.3.41
author | Eris Caffee <discordia@eldalin.com> |
---|---|
date | Tue, 23 Jun 2015 14:52:17 -0500 |
parents | eb159ea69f33 |
children | 80ca1973e3bd |
line diff
1.1 --- a/algs4-c++/src/Queue.cpp Tue Jun 23 12:28:03 2015 -0500 1.2 +++ b/algs4-c++/src/Queue.cpp Tue Jun 23 14:52:17 2015 -0500 1.3 @@ -25,6 +25,13 @@ 1.4 std::cout << *iter << std::endl; 1.5 } 1.6 1.7 + Queue<long> q2( queue ); 1.8 + std::cout << "Copied queue to q2. q2 has " << q2.size() << " entries." << std::endl; 1.9 + for ( auto iter = q2.begin(); iter != q2.end(); ++iter ) { 1.10 + std::cout << *iter << std::endl; 1.11 + } 1.12 + 1.13 + 1.14 std::cout << "Dequeuing entries..." << std::endl; 1.15 1.16 while ( ! queue.is_empty() ) { 1.17 @@ -34,5 +41,9 @@ 1.18 1.19 std::cout << "Queue has " << queue.size() << " entries." << std::endl; 1.20 1.21 + 1.22 + // Silently empty q2 to avoid the assertion in the destructor. 1.23 + while ( ! q2.is_empty() ) 1.24 + q2.dequeue(); 1.25 } 1.26