Question: Q5. [20 marks] Implement a function REVERSE_COPY(Stack S1, Stack S2) in pseudocode to copy the elements of S2 to an empty stack S1 in reverse
![Q5. [20 marks] Implement a function REVERSE_COPY(Stack S1, Stack S2) in](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3d76971718_42466f3d768eb443.jpg)
Q5. [20 marks] Implement a function REVERSE_COPY(Stack S1, Stack S2) in pseudocode to copy the elements of S2 to an empty stack S1 in reverse order. Assuming the S1 and S2 in Fig. 1 are fed to your algorithm, Fig. 2 illustrates the result after REVERSE_COPY(Stack S1, Stack S2). Besides the methods of the Stack ADT, the function COPY(Stack S1, Stack S2) defined in Q4 is also allowed in this question. Finally, give the time complexity of your algorithm. Hint: the contents in S2 should remain unchanged in the end, and you can also use an extra stack S3 to transfer elements. 1 3 4 6 6 4 3 1 Si S2 Fig. 2. The result of Si and S2 after Reverse_COPY(Stack S1, Stack S2)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
