In this recitation, you will practice using stacks by writing code to reverse a stack.
Use ReversibleStack.java and fill in the two empty methods. The reverse method must reverse the values stored in the ReversibleStack object and return a new ReversibleStack object. Do not use arrays, linked lists, array lists, vectors, or queues. Run the program to show the TA that it works correctly. Note that this uses the LinkedStack.java class.
Write a ReversibleStackComposition class. This class should have at least one field: a stack object (it must be of type StackInterface). In addition to push
, pop
, and peek
methods, implement a reverse
method. Just like the reverse
method above, this method should return a stack that is the reverse of the stack field object. The stack field should still have the same order as before the reverse
method was called.
Show the TA that your class works correctly by showing the output of:
This is for your practice. You should be able to complete the first program by the end of recitation, and probably the second program. If you complete a program, call the TA over to look over your program to make sure it is correct. If you do not have time to complete the programs before the end of recitation, you have the option of uploading it to CourseWeb once you are finished to receive feedback on it from the TA. If you upload it after Monday, October 5, please email the TA so he knows to look at it.