Automake the data files.
This commit is contained in:
parent
f1d7bf2957
commit
9bba1bcbd1
|
@ -1,14 +1,25 @@
|
||||||
|
# data files
|
||||||
data/corpus.txt
|
data/corpus.txt
|
||||||
|
data/cpp
|
||||||
|
data/ods-cpp.tgz
|
||||||
|
|
||||||
|
# autotools junk files
|
||||||
|
.deps
|
||||||
|
Makefile
|
||||||
Makefile.in
|
Makefile.in
|
||||||
aclocal.m4
|
aclocal.m4
|
||||||
autom4te.cache/
|
autom4te.cache/
|
||||||
compile
|
compile
|
||||||
config.guess
|
config.*
|
||||||
config.sub
|
|
||||||
configure
|
configure
|
||||||
depcomp
|
depcomp
|
||||||
install-sh
|
install-sh
|
||||||
|
libtool
|
||||||
ltmain.sh
|
ltmain.sh
|
||||||
m4/
|
m4/
|
||||||
missing
|
missing
|
||||||
src/Makefile.in
|
|
||||||
|
# build artifacts
|
||||||
|
src/*.o
|
||||||
|
src/ch??ex??
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
ACLOCAL_AMFLAGS = -I m4
|
ACLOCAL_AMFLAGS = -I m4
|
||||||
SUBDIRS = src
|
SUBDIRS = src data
|
||||||
|
|
|
@ -9,7 +9,7 @@ AC_INIT([ods],
|
||||||
AM_INIT_AUTOMAKE([1.11 foreign])
|
AM_INIT_AUTOMAKE([1.11 foreign])
|
||||||
|
|
||||||
AC_CONFIG_SRCDIR([src/ch01ex01.cc])
|
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])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
|
|
||||||
PKG_PROG_PKG_CONFIG
|
PKG_PROG_PKG_CONFIG
|
||||||
|
|
|
@ -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
|
|
@ -132,6 +132,10 @@ Run times come in three flavours:
|
||||||
and pop() operations. Show how, using only a FIFO Queue, q, you can
|
and pop() operations. Show how, using only a FIFO Queue, q, you can
|
||||||
reverse the order of all elements in s.
|
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),
|
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
|
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
|
stored. The find(x) operation in a Bag returns some element (if any) that
|
||||||
|
@ -148,4 +152,4 @@ Run times come in three flavours:
|
||||||
remove(i) in your List implementation. Think about how you could improve
|
remove(i) in your List implementation. Think about how you could improve
|
||||||
the performance of the find(x) operation in your USet and SSet
|
the performance of the find(x) operation in your USet and SSet
|
||||||
implementations. This exercise is designed to give you a feel for how
|
implementations. This exercise is designed to give you a feel for how
|
||||||
difficult it can be to obtain efficient implementations of these interfaces
|
difficult it can be to obtain efficient implementations of these interfaces
|
||||||
|
|
|
@ -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 += -Wunused-variable -std=c++14 -D_XOPEN_SOURCE -O0 -g -I.
|
||||||
AM_CPPFLAGS += -fno-elide-constructors -Weffc++
|
AM_CPPFLAGS += -fno-elide-constructors -Weffc++
|
||||||
|
|
||||||
bin_PROGRAMS := ch01ex01 ch01ex03
|
bin_PROGRAMS := ch01ex01 ch01ex03 ch01ex04
|
||||||
ch01ex01_SOURCES := ch01ex01.cc
|
ch01ex01_SOURCES := ch01ex01.cc
|
||||||
ch01ex03_SOURCES := ch01ex03.cc
|
ch01ex03_SOURCES := ch01ex03.cc
|
||||||
|
ch01ex04_SOURCES := ch01ex04.cc
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -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;
|
||||||
|
};
|
Loading…
Reference in New Issue