CSci 2101 Problem set 2. Java stacks.

Due Friday, May 28th at 11:59pm (by e-mail)

25 points

You may work individually or in pairs.

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). 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, 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").
Also important: 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.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.