CSCI 1321 (Principles of Algorithm Design II):
Sample Programs
- Sample Makefile
for compiling C++ with warning flags, etc.
- Recursion example -- computing powers (August 30):
power-fcn.cpp.
- Command-line arguments example -- echo arguments
(September 4):
echo1perline.cpp.
- Command-line arguments example -- summing arguments
(September 4):
addargs.cpp.
- Recursion example revisited -- computing powers (September 6):
power-fcn2.cpp.
- Recursion example -- printing numbers in reverse order
(September 6):
reverse-print.cpp.
- Recursion example -- searching in array (September 6):
in-array.cpp.
- Recursion example -- counting alphabetic characters in
(C-style) string (September 6):
count-alpha.cpp.
- Example of using Seq (list) template class
(September 13):
list-example.cpp.
(To run this example, you will also need files
seq.h and seq.cpp.
You are not required to read and understand the code in these
files.)
- Recursion example -- search-and-replace in list of strings
(September 18):
subst.cpp.
- Template-class example -- 3D vectors (September 18):
non-template version
int-vector-1.cpp
and version converted to template class
template-vector-1.cpp.
- Function-parameters example -- 3D vectors (September 20):
version with the same functionality as before
int-vector-2.cpp
and version that adds dot product
int-vector-3.cpp.
- Example of using STL vector template class
(September 25):
vector-use-example.cpp.
- Example of using STL pair template class
(September 25):
pair-use-example.cpp.
- Example of using several STL functions -- "shopping cart" class
(September 25 -- October 4):
example use
shoppingCart-use.cpp
and class definition
shoppingCart.h.
- Example of using several STL functions -- case-insensitive sort
(October 4):
print-sorted.cpp.
- Example of defining a class, with some overloaded operator
functions -- simplified list-of-characters class
(October 16):
example use
use-list.cpp
and class definition
list.h.
- Example of using dynamically-allocated memory -- a program
that needs an "expandable array" (October 25):
First version using an STL vector
column-print-1.cpp,
second version using a fixed-size array
column-print-2.cpp,
and third version using dynamically-allocated arrays
column-print-3.cpp.
- Example of class using dynamically-allocated memory (October 30):
example use
dArray-use.cpp
and class definition
dArray.h.
- Doubly-linked list class and example of use
(November 1, November 8):
string-editor application program
editor.cpp,
buffer class definition
buffer.h,
and doubly-linked list class definition
dll.h.
- Double-ended queue (deque) class and test program
(November 13):
test program
deque-test.cpp
and class definition
deque.h.
- Doubly-linked list class, revised to provide iterators,
and example of use (November 15):
string-editor application program
editor-2.cpp,
buffer class definition
buffer-2.h,
and doubly-linked list class definition
dll-2.h.
- Example of using Tree template class
(November 27):
tree-use.cpp.
(To run this example, you will also need file
tree.h.
You are not required to read and understand the code in these
files.)
- Functions for binary search trees
(December 4):
function definitions
bst.h
(notice that they
are template functions)
and example use program
bst-use.cpp.