2000 Jan 15
Andrew Koenig presents a Lisp-like linked list C++ class in chapter 15 of Ruminations on C++. This is a short introduction to using the class (header file and implementation file).
Unlike some programming languages, the C++ programming language requires explicit type declarations. Thus, in the following, I will refer to lists of ints, but lists of any other type can also be created.
A list is
To create an empty list, use
To add an integer, e.g., 3, to the an existing list L, use
To obtain a list L's first item, which has int type, use
The subst function substitutes one string for another string in a linked list of strings.
To use the linked list class with a program you wrote, copy the two files (header file and implementation file) to the directory containing the program's C++ code. One way to do this is to use the ``Save As...'' item on a WWW browser's file menu.
Another way is to issue the shell command wget http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/SamplePrograms/seq.h http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/SamplePrograms/seq.cpp . The wget program copies the specified WWW links to your local directory. See also the wget manual. Isn't wget slick?
In your C++ program, add the line