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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!