两个stack实现逆序
public static void main(String[] args) {
Stack<Integer> stack=new Stack<>();
for(int i=5;i>0;i--){
stack.push(i);
}
System.out.println(stack.peek()+"******");
sort(stack);
}
private static void sort(Stack<Integer> stack){
Stack<Integer> help=new Stack<>();
while (!stack.isEmpty()){
int current=stack.pop();
if(!help.isEmpty()&&help.peek()>current){
stack.push(help.pop());
}
help.push(current);
}
System.out.println();
System.out.println(help.peek()+"peek");
}
}