3.6---双栈排序(CC150)

答,课本上的方法比较好。

    public static Stack<Integer> sort(Stack<Integer> s) {
        Stack<Integer> r = new Stack<Integer>();
        while(!s.isEmpty()) {
            int tmp = s.pop();
            while(!r.isEmpty() && r.peek() > tmp) {
                s.push(r.pop());
            }
            r.push(tmp);
        }
        return r;
    }

 

posted @ 2015-12-21 22:09  创业-李春跃-增长黑客  阅读(139)  评论(0编辑  收藏  举报