CSCI 1321 (Principles of Algorithm Design II):
Sample Programs
Sample programs presented in class.
- Sample Makefile
for compiling C++ with warning flags, etc.
- Recursion example -- computing powers (January 10):
power-fcn.cpp.
- Command-line arguments example -- summing arguments
(January 12):
sumpgm.cpp.
- Recursion example -- printing input in reverse order
(January 12):
reverse-and-print.cpp.
- Recursion example -- counting alphabetic characters in
a string (January 15):
count-alpha.cpp.
- Recursion example -- checking for element in an array
(January 15):
in-array.cpp.
- Example of using string class (January 19):
string-use-example.cpp.
- Recursion example -- reverse lines in file (January 19):
reverse-file.cpp.
- Template list class and example of use (January 22):
- Shopping-list example (January 24, 26):
- 3D vector example (January 29, 31; March 1):
- Class for 3D vector of ints, version 1:
int-vector-1.cpp.
- Template class for 3D vector, version 1:
template-vector-1.cpp.
- Class for 3D vector of ints, version 2, showing
use of function parameters:
int-vector-2.cpp.
- Class for 3D vector of ints, version 3, showing
another use of function parameters:
int-vector-3.cpp.
- Class for 3D vector of ints, version 4, showing
use of STL functions as function parameters
int-vector-4.cpp.
- Example of using STL vector class (February 7):
vector-use-example.cpp.
- Example of using STL pair class (February 7):
pair-use-example.cpp.
- Example of using STL iterators and sort() function
(February 16):
print-sorted.cpp.
- Shopping-cart class example, showing definition of class and
more use of STL functions (various dates):
- Additional examples of using STL functions and classes
(February 19):
- Print-in-two-columns example (March 5):
- Simple dynamic-array class (March 9):
- Doubly-linked list class and string editor program
(March 21, 23, 26):
- Doubly-linked list class definition
dll-1.h.
- "Buffer" (list of characters plus cursor) class
definition
buffer-1.h.
- String editor program
editor-1.cpp.
- Doubly-linked list class and string editor program, version 2
(not presented in class):
- Doubly-linked list class definition
dll-2.h.
with "pred()" and "succ()" functions added.
- "Buffer" (list of characters plus cursor) class
definition
buffer-2.h.
- String editor program
editor-2.cpp.
This version includes additional
member functions helpful for Homework 6.
- Double-ended queue class:
- Doubly-linked list class and string editor program, version 3
(April 2):
- Doubly-linked list class definition
dll-3.h.
- "Buffer" (list of characters plus cursor) class
definition
buffer-3.h.
- String editor program
editor-3.cpp.
This version is a template class and includes an iterator
member class.
- Template tree class and example of use (April 11):
- Functions for binary search tree and example of use
(April 16):