Automake the data files.

This commit is contained in:
2017-12-19 21:53:51 +00:00
parent f1d7bf2957
commit 9bba1bcbd1
8 changed files with 94 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ AM_CPPFLAGS += -Wwrite-strings -Wmissing-declarations -Wno-long-long -Werror
AM_CPPFLAGS += -Wunused-variable -std=c++14 -D_XOPEN_SOURCE -O0 -g -I.
AM_CPPFLAGS += -fno-elide-constructors -Weffc++
bin_PROGRAMS := ch01ex01 ch01ex03
bin_PROGRAMS := ch01ex01 ch01ex03 ch01ex04
ch01ex01_SOURCES := ch01ex01.cc
ch01ex03_SOURCES := ch01ex03.cc
ch01ex03_SOURCES := ch01ex03.cc
ch01ex04_SOURCES := ch01ex04.cc

43
src/ch01ex04.cc Normal file
View File

@@ -0,0 +1,43 @@
#include <iostream>
#include <queue>
#include <stack>
#include <string>
using namespace std;
static void
print_queue(queue<int>& q)
{
while (!q.empty()) {
cout << q.front() << " ";
q.pop();
}
cout << endl;
}
int
main(int argc, char *argv[])
{
stack<int> s;
queue<int> q;
for (int i = 1; i < argc; i++) {
string line(argv[i]);
int arg = stoi(line);
s.push(arg);
}
while (!s.empty()) {
// NB: the pop() interface in the book returns the topmost
// element while removing it; the C++ STL interface does
// not, requiring the separate top() and pop() invocations.
int arg = s.top();
s.pop();
q.push(arg);
}
print_queue(q);
}

15
src/ch01ex05.cc Normal file
View File

@@ -0,0 +1,15 @@
#include <iostream>
#include <vector>
// Using a USet, implement a Bag. A Bag is like a USet supports the add(x),
// remove(x), and find (x) methods — but it allows duplicate
// elements to be stored. The find(x) operation in a Bag returns some element (if any) that is equal to x. In addition,
// a Bag supports the findAll(x) operation that returns a list of all elements in the Bag that are equal to x.
template<typename T>
class Bag {
public:
private:
vector<T> v;
};