Automake the data files.

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

17
.gitignore vendored
View File

@ -1,14 +1,25 @@
# data files
data/corpus.txt
data/cpp
data/ods-cpp.tgz
# autotools junk files
.deps
Makefile
Makefile.in
aclocal.m4
autom4te.cache/
compile
config.guess
config.sub
config.*
configure
depcomp
install-sh
libtool
ltmain.sh
m4/
missing
src/Makefile.in
# build artifacts
src/*.o
src/ch??ex??

View File

@ -1,2 +1,2 @@
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src
SUBDIRS = src data

View File

@ -9,7 +9,7 @@ AC_INIT([ods],
AM_INIT_AUTOMAKE([1.11 foreign])
AC_CONFIG_SRCDIR([src/ch01ex01.cc])
AC_CONFIG_FILES([Makefile src/Makefile])
AC_CONFIG_FILES([Makefile src/Makefile data/Makefile])
AC_CONFIG_MACRO_DIR([m4])
PKG_PROG_PKG_CONFIG

12
data/Makefile.am Normal file
View File

@ -0,0 +1,12 @@
pkgdata_DATA = corpus.txt ods-cpp/main.cpp
corpus.txt: corpus.txt.gz
gzip -d -k $@.gz
ods-cpp/main.cpp: ods-cpp.tgz
tar xzf ods-cpp.tgz
ODS_SAMPLE_CODE_URL := http://opendatastructures.org/ods-cpp.tgz
ods-cpp.tgz:
if command -v curl 2>&1 > /dev/null ; then curl -L -O $(ODS_SAMPLE_CODE_URL) \
elif command -v curl 2>&1 > /dev/null ; then wget $(ODS_SAMPLE_CODE_URL) ; fi

View File

@ -132,6 +132,10 @@ Run times come in three flavours:
and pop() operations. Show how, using only a FIFO Queue, q, you can
reverse the order of all elements in s.
See src/ch01ex04.cc: you just pop each element from the stack → queue,
then pop the elements off the queue. If you wanted to reverse the stack
itself, you'd just push the elements back onto the stack.
5. Using a USet, implement a Bag. A Bag is like a USet—it 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

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
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;
};