The goal of this project is to practice using pointers for programming in C.
In this project, you will be doing something familiar (implementing stacks two ways: with an array and as a linked list) in a manner unfamiliar (using dynamic arrays and pointers in C). You will be writing two library files (each with both a header and source file) to implement stacks. In either case, you will write a struct that represents the stack itself and a series of functions which provide the behavior of the stack.
Copy the driver program
cp /homeemp/tvandrun/pub/245/cfun/stackdriver.c .
First, open the driver program and look it over. You'll see that it expect the following things:
arraystack.h
or liststack.h
.
You will write both, and you can test them alternately by commenting out
and un-commenting the relevant lines.
ArrayStack
or ListStack
.
This will have to be a struct type.
makeStack()
function
which takes an integer indicating a maximum size for the stack
and returns a pointer to a newly allocated stack.
The list stack can ignore the maximum size (it can grow unbounded).
push()
,
pop()
, and top
, but notice that
these take a pointer to the stack as a parameter--- they can't be
like instance methods.
destroyStack()
,
which deallocates the stack.
Then, write the two libraries. Remember what we learned about how to compile and link. Be careful on your use of pointers and your allocating and deallocating.
Turn in a hard copy of a typescript where you compile and run both versions. For the array version, run your program twice, once where the user enters data until the stack is full, and the other where the user quits by entering -1.
DUE:Thursday, April 26, 5:00 pm.
ALSO: No projects will be accepted after Friday, April 26, 5:00 pm, even if you have two late days left.