首页 > 其他 > 详细

CC150 : Sort Stack

时间:2015-02-26 09:45:32      阅读:280      评论:0      收藏:0      [点我收藏+]
可以使用一个extra的stack。
 
 1 class Solution {
 2     public Stack<Integer> sortStack(Stack<Integer> s1) {
 3         Stack<Integer> s2 = new Stack<Integer>();
 4         while(!s1.isEmpty()) {
 5             int temp = s1.pop();
 6             while(!s2.isEmpty() && s2.peek() > temp) {
 7                 s1.push(s2.pop());
 8             }
 9             s2.push(temp);
10         }
11         return s2;
12     }
13 }

 

 

CC150 : Sort Stack

原文:http://www.cnblogs.com/diyishao/p/4300567.html

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