CS170
Programming Assignment #1
DUE : Thursday 2/6, 11:00pm.
Implement a stack abstract data type in C. Your stack should be capable
of holding integer values. Hide the implementation of the stack from the
client via the incomplete type facility of ANSI C.
The implementation of the stack must be as
a linked list. Be sure that the stack functions allocate and
deallocate memory appropriately. As a model, use the queue ADT
and implementation discussed in lecture.
The queue ADT as discussed in lecture can be downloaded
in the following files:
Your program MUST follow these specifications:
- The I/O behavior must be an "interpreter"-like interface in which
the program prompts the user for an expression, and the program responds
with the current state of the stack. The commands must be "i" for
push (can't use "p" for two things!), "p" for pop, and "q" for quit.
The behavior of the program must be exactly as illustrated
in the sample run here.
Note this does of course require re-writing the existing
main.c
, not simply changing it to reflect the new ADT.
- Change the data type so that it is appropriate
for stacks! In particular, change names appropriately
(you shouldn't still call it an
IntQueue
for example),
and also the implementation, which we expect to be simpler.
- Your makefile, and your executable, must work at the command line on the
lab's Linux partition. Note that if you use an IDE such as Netbeans or
Xcode (which
generate their own Makefiles automatically), this will probably require that you create an appropriate
Makefile by hand (which is easy, since it's just an adaptation of the one
given above). The executable file must be named
exec
,
as it was for the queue type.
Be sure to document your code carefully and appropriately.
You can test your program with this file.
Add it to the folder in which you build the project,
and at the Linux prompt, just type ./exec < input1.txt.
The output should be this.
Create a .zip of a folder named StackProject
containing the files Stack.h, Stack.c, main.c,
and Makefile
.
Submit it at
this location.
Back to CS170 Assignments.