Sunteți pe pagina 1din 1

Problem 1

Two stacks are the same if they have the same size and their elements at the corresponding
positions are the same. Please do the following:

Add the method equalStack to Class StackClass that takes as a parameter of a StackClass
object, say otherStack and return true if the stack is the same as otherStack (Note: In
StackClass.java, you can have - public boolean equalStack(StackClass<T> otherStack,
which needs to be complete).

Write a program to test your method.

Problem 2
For the stack class, please enhance it by the following:

Add the following operation to the Class StackClass:


void reverseStack(StackClass<T> otherStack);
This operation copies the elements of a stack in reverse order onto another stack.
Consider the following statements:
StackClass<T> stack1;
StackClass<T> stack2;
The statement
stack1.reverseStack(stack2);
This statement will copy the elements of stack1 onto stack2 in the reverse order. That is,
the top element of stack1 is the bottom element of stack2, and so on. The old contents of
stack2 will be destroyed and stack1 will not be changed.

Write a program to test the method reverseStack.

S-ar putea să vă placă și