Question
Write a method called copyStack that copies the contents of one stack into another (which is not empty). The method must take as parameter a
Write a method called copyStack that copies the contents of one stack into another (which is not empty). The method must take as parameter a source stack and Boolean flag reverse and copy the contents of the given stack into a destination stack and return the same. Your method should also allow the source stack to be copied in reverse order based on the value of the flag reverse. If reverse is true, the source stack should be copied in reverse order. If reverse is false, the content on source stack is placed in destination stack in such a way that the final stack would maintain the original order of the data.
Write the code in java and explain it to me.Thanks.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started