P16250 [GeeksforGeeks] Reverse a stack
普及
题目描述

You are given a stack St. You have to reverse the stack using recursion.
Example 1:
Input:
St = {3,2,1,7,6}
Output:
{6,7,1,2,3}
Example 2:
Input:
St = {4,3,9,6}
Output:
{6,9,3,4}
Your Task:
You don't need to read input or print anything. Your task is to complete the function Reverse() which takes the stack St as input and reverses the given stack.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1 <= size of the stack <= 10^{4}
-10^{9} <= Each element of the stack <= 10^{9}
Sum of N over all test cases doesn't exceeds 10^{6}
Array may contain duplicate elements.

输入格式

见题面

输出格式

见题面

样例输入
St = {3,2,1,7,6}
样例输出
{6,7,1,2,3}