import java.util.Objects;
import java.util.Stack;
class Solution {
private Stack<Integer> secondStack = new Stack<>();
public void sort(Stack<Integer> stack) {
if (Objects.isNull(stack) || stack.isEmpty()) {
return;
}
while (! stack.isEmpty()) {
int a = stack.pop();
while (! secondStack.isEmpty() && a < secondStack.peek()) {
stack.push(secondStack.pop());
}
secondStack.push(a);
}
while (! secondStack.isEmpty()) {
stack.push(secondStack.pop());
}
}
}
转载于:https://blog.51cto.com/tianyiya/2313532