view algs4-c++/src/Stack.cpp @ 18:a149b424b4e2

Updated all template classes to have the implementaiton in the header file.
author Eris Caffee <discordia@eldalin.com>
date Sat, 20 Jun 2015 19:36:11 -0500
parents 8af1a61be7c1
children
line source
1 // g++ -std=c++11 Stack.cpp
4 #include "Stack.hpp"
6 #include <iostream>
8 int main ( int argc, char **argv ) {
10 Stack<long> stack;
12 long i;
13 while ( ! std::cin.eof() ) {
14 std::cin >> i;
15 if ( std::cin.good() )
16 stack.push(i);
17 }
19 std::cout << "Stack has " << stack.size() << " entries." << std::endl;
21 for ( auto iter = stack.begin(); iter != stack.end(); ++iter ) {
22 std::cout << *iter << std::endl;
23 }
25 #ifdef EXERCISES
26 std::cout << "Looking for 3: " << ( stack.find( 3 ) ? "found" : "not found" ) << std::endl;
27 std::cout << "Looking for 9999: " << ( stack.find( 9999 ) ? "found" : "not found" ) << std::endl;
29 std::cout << "Removing bottom entry: ";
30 i = stack.delete_bottom();
31 std::cout << i << std::endl;
32 std::cout << "Stack has " << stack.size() << " entries." << std::endl;
34 for ( auto iter = stack.begin(); iter != stack.end(); ++iter ) {
35 std::cout << *iter << std::endl;
36 }
38 std::cout << "Removing entry 2: ";
39 i = stack.remove( 2 );
40 std::cout << i << std::endl;
41 std::cout << "Stack has " << stack.size() << " entries." << std::endl;
43 for ( auto iter = stack.begin(); iter != stack.end(); ++iter ) {
44 std::cout << *iter << std::endl;
45 }
47 #endif
49 std::cout << "Popping entries..." << std::endl;
51 while ( ! stack.is_empty() ) {
52 i = stack.pop();
53 std::cout << i << std::endl;
54 }
56 std::cout << "Stack has " << stack.size() << " entries." << std::endl;
58 }