Mercurial > Algorithms__Sedgewick
diff algs4-c++/src/RandomQueue.cpp @ 19:60fb85712482
Problems 1.3.35 and 36
author | Eris Caffee <discordia@eldalin.com> |
---|---|
date | Mon, 22 Jun 2015 14:07:01 -0500 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/algs4-c++/src/RandomQueue.cpp Mon Jun 22 14:07:01 2015 -0500 1.3 @@ -0,0 +1,41 @@ 1.4 +// g++ -std=c++11 RandomQueue.cpp 1.5 + 1.6 +#include <iostream> 1.7 + 1.8 +#include "RandomQueue.hpp" 1.9 + 1.10 +int main ( int argc, char **argv ) { 1.11 + 1.12 + RandomQueue<long> q; 1.13 + 1.14 + long i; 1.15 + while ( ! std::cin.eof() ) { 1.16 + std::cin >> i; 1.17 + if ( std::cin.good() ) { 1.18 + q.enqueue(i); 1.19 + } 1.20 + } 1.21 + 1.22 + std::cout << "RandomQueue has " << q.size() << " entries." << std::endl; 1.23 + 1.24 + for ( auto iter = q.begin(); iter != q.end(); ++iter ) { 1.25 + std::cout << *iter << std::endl; 1.26 + } 1.27 + 1.28 + std::cout << "Sampling entries." << std::endl; 1.29 + 1.30 + for ( int i; i < q.size(); ++i ) { 1.31 + std::cout << q.sample() << std::endl; 1.32 + } 1.33 + 1.34 + std::cout << "Removing entries entries..." << std::endl; 1.35 + 1.36 + while ( ! q.is_empty() ) { 1.37 + i = q.dequeue(); 1.38 + std::cout << i << std::endl; 1.39 + } 1.40 + 1.41 + std::cout << "Q has " << q.size() << " entries." << std::endl; 1.42 + 1.43 + } 1.44 +