Ask your own question, for FREE!
Mathematics 25 Online
OpenStudy (anonymous):

Write a recursive, non-destructive equals method that determines if one stack is equal to another stack (i.e. they contain the same items in the same order). A method is considered non-destructive if all objects are left in their original condition after the method is called as they were before the method was called. Note that this is not an instance method of the Stack class, so you do not have access to the internal data structure of the Stacks. static boolean equals(Stack first,Stack second) { I'm working in Java and I'm confused as to how to make this work.

OpenStudy (anonymous):

I'm thinking you also need to save the elements you pop off both stacks when you compare them, and somehow add them back into the stack. However if you just keep adding them back in right away, you'll be stuck comparing the first two elements forever. The stack operations are push, pop, and isEmpty

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!