CSci 2101 Problem set 2. Java stacks.

Due Wednesday, September 14th at 11:59pm (by e-mail)

25 points

You may work individually or in pairs.

General requirements:

Copying a stack (10 points)

Write a method that takes a stack of Integers and creates and returns a copy of this stack, i.e. a stack that has the exact same elements in the same order. The given stack must be unchanged when the method is finished (make sure to print it out at the end to check this condition). Please include your test data when submitting the program (it may be commented out).
Hint: think of additional storage that you need for this task.

Checking if two stacks are equal (15 points)

Write a method that takes two stack of Integers and returns "true" when the two stacks contain the same elements in the same order and "false" otherwise. The two stacks must be in the original order when the method finishes (regardless of whether the stacks were the same or not). You might want to write a recursive function for this problem, but you don't have to.
Important: the program must work without a run-time error (for instance, when one of the stacks is empty and the other one is not, it should return "false"). Carefully handle all cases when one stack has fewer elements than the other one.
Please submit all of your test data.

How to submit

Submit your Java file(s) to me by e-mail. The subject must be Problem Set N, where N is the problem set number. If working in a group, CC your group partner.


CSci 2101 course web site.