The bounded stack of Lab 3 has a severe limitation: a bounded stack cannot grow beyond its initial size. This limitation will be removed in Lab 4. You are to write an unbounded stack using a linked list, i.e., using dynamic memory allocation. The linked list implementation will be hidden as much as possible from the stack.
Note that changes only affect the stack representation and not the
stack interface. You are to re-implement the methods that operate
upon objects of class
Stacktemplate class (Stack.h) that is part of the distribution for this lab. Do not vary from this specification.
Historytemplate class (History.h) that is part of the distribution for this lab. For the most part, you don't need to be concerned with the details of the
Historytemplate class. But, you need to understand the information that it presents.
Given a specification for a Stack class, write the methods and
operators for that class. The class represents an ADT with operations
is_full. Use a simple
singly linked list structure for the implementation.
Develop an implementation for a linked list using the specification of
Node class given in (Node.h).
you can either keep this specification intact as an undisturbed file,
or put it into your
Stack.cc implementation file.
Therefore, stack clients won't have access to the implementation at
In addition, use the History template class to check for memory leaks.
To use it, your
Node template class must be instrumented
by deriving from
History. This has already been done in
A test driver program is supplied (
but you must extend it to completely test your
implementation. Your implementation must check for error conditions,
such as attempting to pop off an empty stack or push on to a full
stack, and failing to allocate dynamic memory. The distributed
main.cc is almost the same as that of Lab 3 (with
the exception of the explicit template instantiations, which you
probably don't use), so you should be able to reuse your Lab 3
Be sure that
check whether the stack is empty or full, as appropriate. They return
0 for success, or -1 if the stack was already full when attempting to
push, or empty when attempting to
NOTE your definition (in Stack.cc) of the
(size_t) constructor must omit the default parameter. The
default parameter is only used in the method declaration, in Stack.h.
And, the definition should omit the parameter name (but not the type)
to avoid a compiler warning about an unused parameter. So, you can
define the constructor this way:
template <class T>
// your code here
NOTE An unbounded stack is never full. Your
is_full method should be implemented accordingly.
NOTE Even though an unbounded stack is never full,
push method still needs to return -1 if for some
other reason the value could not be pushed on the stack (hint: memory
NOTE You must define the
read method so
that it replaces the contents of the stack with the
values read in.
NOTE You must define the
read methods so that they are duals of one another. That
is, if a stack's print method is called with a given iostream, and
then the read method of any other stack (no matter what it contains)
is called immediately after with the same iostream, then at that point
the two stacks must be equivalent. How you do this is up to you, but
one suggested approach is to print/read the number of elements first,
then the value of each element (hint: the order in which you print and
read the values can make the read method in particular either easier
or harder to implement).
~cs342/bin/lab4. That will copy several files to a new
lab4subdirectory. You can
cd lab4and enter
maketo compile the code, if you like. However, it will not link until your implementation is filled in.
NOTE: you can use the distribution mechanism to
revert one or more of your files at any time. First, delete the file
mv it to a file with a different name, such
Stack.cc.BAD). Then, run
cvs update to
update your workspace. That will replace any missing files. It will
also let you know of any files that you modified but did not delete.
cvs is in pkg
gnu, in case you don't find it
After obtaining the Lab 4 distribution, copy your
Stack.cc files from your Lab 3 to your
directory and modify as necessary. And copy your
from Lab 3, and try to use it with as little modification as possible.
You will need to implement the
Node methods in
readme) documenting what you did to satisfy this assignment.
readmecontains a suggested list of sections that you might provide. Please replace the comments in  with your descriptions. Specifically mention what the most troublesome parts were. These files will be submitted automatically when you execute the command:
NOTE: there is a Makefile target that allows you to test what you are going to turn in:
It places the output that will be
turned in into the
TEST_TURNIN directory. Please use
make test_turnin, and verify that the files that you will
submit are correct.