Homework #6
- Goal: Learning the concept of public
member functions and how they are
used.
- Please UPLOAD your homework (ZIP or RAR file) to TA at
http://ms11.voip.edu.tw/cs102/
- Deadline: 2008/3/28 11:00 AM
-
(From: Exercise 7 on P.398)
Define a class to represent a push-down
stack of integers. A stack is a list of items that permits
adding ('pushing') or removing ('popping') items only from one end
and works on a last-in, first-out principle. For example, if the
stack contained [10 4 16 20], pop() would return 10, and the stack
would then contain [4 16 20]; a subsequent push(13) would leave the
stack as [13 4 16 20]. You can't get an item that is not at the top
without first popping the ones above it. Your class should implement
push() and pop() functions, plus a print() function so that you can
check the stack contents. For now, store the list internally as an
array. Write a test program to verify the correct operation of your
class.