public static void sortStack(Stack<Integer> stack){
Stack<Integer> help = new Stack<>();
while(!stack.isEmpty()){
Integer curr = stack.pop();
while(!help.isEmpty()&&help.peek()<curr){
stack.push(help.pop());
}
help.push(curr);
}
while(!help.isEmpty()){
stack.push(help.pop());
}
}
网友评论