import java.util.*;
public class ReverseStack {
// [1,2,3,4,5],5
public int[] reverseStackRecursively(int[] stack, int top) {
// write code here
r(stack, top - 1, 0);
return stack;
}
private void r(int[] stack, int top, int bot) {
if (top < bot) {
return;
}
int curEle = stack[bot];
System.out.println(curEle);
r(stack, top, bot + 1);
stack[top - bot] = curEle;
}
}

京公网安备 11010502036488号