首页 > 编程语言 > 详细

3.6---双栈排序(CC150)

时间:2015-12-21 23:26:40      阅读:254      评论:0      收藏:0      [点我收藏+]

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

    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;
    }

 

3.6---双栈排序(CC150)

原文:http://www.cnblogs.com/yueyebigdata/p/5065033.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!