5

public class Solution {
    public static void sortStackByStack(Stack<Integer> stack){
        Stack<Integer> help=new Stack<Integer>();
        while(!stack.isEmpty()){
            int cur=stack.pop();
            while(!help.isEmpty() && help.peek()<cur){
                stack.push(help.pop());
            }
            help.push(cur);
        }
        while(!help.isEmpty()){
            stack.push(help.pop());
        }
    }
}

 

posted @ 2018-09-28 08:55  chan_ai_chao  阅读(144)  评论(0编辑  收藏  举报