int getStackBottomDate(Stack<Integer> stack) {
int result = stack.pop();
if (stack.isEmpty()) {
return result;
} else {
int last = getStackBottomDate(stack);
stack.push(result);
return last;
}
}
void reverseStack(Stack<Integer> stack) {
if (stack.isEmpty()) {
return;
}
int res = getStackBottomDate(stack);
reverseStack(stack);
stack.push(res);
}
网友评论