CS112 Homework 6

Reading for the week:
Chapter 7.
Homework 6a, due Monday October 20, 1997.
Write a LIFO stack class using arrays as shown in class. A little stack testing program is available. The stack should have the following methods:
       public static number_of_stacks ()
       // Returns the total number of stacks created so far.

       public void push (int v);
       public int pop ();
       public int peek ();
       public boolean isempty ();
       
You should initially allocate 100 stack elements, but your stack code must correctly handle the case where more than 100 elements are pushed onto the stack. (That is, you must grow the stack.)

Submit stack.java

Remember to turn in a .class file for every .java file you turn in.

Homework 6b, due Wednesday October 22, 1997.
Modify your stack program to hold a stack of Strings instead of a stack of ints. Rewrite your reverselines program to use a stack: Every line that is read in should be pushed onto the stack, and then when end-of-file is found, the stack should be popped and printed and popped and printed.

Submit stack.java and reverselines.java.

Homework 6c, due Friday October 24, 1997.
Write a stack using lists as shown in class on Friday 10/17. Demonstrate that it works with your stack-oriented reverselines.java

Submit stack.java and reverselines.java.

Don't forget to turn in your auxilliary classes, such as list.java. The name of those classes is not so important to us as the name of the stack class. Why do you think that is so?


Bradley C. Kuszmaul (bradley@arch.cs.yale.edu)
Last modified: Sat Oct 18 23:40:19 1997