fw 3.6 - stack sort- java version - 2013年12月16日23:23:32
来源:互联网 发布:java在线考试系统源码 编辑:程序博客网 时间:2024/04/28 19:55
package test_kepler;import java.util.Stack;public class StackSort { Stack<Integer> o_stack;Stack<Integer> b_stack;Stack<Integer> r_stack;public StackSort(){o_stack = new Stack<Integer>();b_stack = new Stack<Integer>();r_stack = new Stack<Integer>();}public void push(int i){o_stack.push(i);}public int pop(){return o_stack.pop();}//o_stack<->r_stack;public void sort_stack(){int i = 0;while(o_stack.size()!= 0 || b_stack.size()!= 0){++i;int min = 0;if(o_stack.size()!=0){//o_stack->b_stack;min = o_stack.pop();while(o_stack.size()!=0){int t = o_stack.pop();if(t>min){b_stack.push(t);}else{b_stack.push(min);min = t;}}r_stack.push(min);}else{//b_stack->o_stackif(b_stack.size()!=0){min = b_stack.pop();while(b_stack.size()!=0){int t = b_stack.pop();if(t>min){o_stack.push(t);}else{o_stack.push(min);min = t;}}r_stack.push(min);}}}o_stack=r_stack;}// standard solutionpublic 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; }public static void main(String[] args){StackSort ss = new StackSort(); int a[] = {1,23,-2,-43,-243,-33,3332}; for(int i = 0;i<7;++i) { ss.push(a[i]); } ss.sort_stack(); for(int i = 0;i<7;++i) { System.out.println(ss.pop()); }}}
0 0
- fw 3.6 - stack sort- java version - 2013年12月16日23:23:32
- fw - dfs: stack/recursive ; bfs : stack/recursive- java version - 2013年12月20日18:37:18
- fw-2013年12月16日16:54:13 - haino tower via stack -java
- fw - pre_order_traverse - 2013年12月17日13:36:58 - java version
- fw 3.5 -2013年12月16日21:02:12 - two stacks make a queue- java version -
- FW-stack sort- 12/17/2013 C++ version
- fw-2013年12月16日19:48:30 - haino tower - C++ version
- FW-binary - tree - with id and sibling connected - java version 2013年12月18日1:21
- FW-4.2- decide whether the two nodes have circle - JAVA VERSION - 2013年12月20日20:22:25
- fw ->>>>>>> 2013年12月13日23:16:30 ->> quick_sort
- fw-3.5 - queue by 2 stacks - C++ version - 2013年12月16日21:20:06
- FW - java - Adjacency list- 2013年12月19日15:42:04- BFS - edge Node
- fw 2013年12月14日12:51:42 selection_sort
- 2015年7月11日-FW
- fw -BFS & DFS tree-2-013年12月17日17:56:33
- fw12013年12月13日1:17:54 - multi-stack -java
- Java学习笔记(2013年03月23日)
- java基础 16年2月23日
- UNIX 的cat命令
- ALSA声卡驱动中的DAPM详解之一:kcontrol
- Android应用自动更新功能实现使用AsyncTask!
- ALSA声卡驱动中的DAPM详解之二:widget-具备路径和电源管理信息的kcontrol
- Xcode4快速Doxygen文档注释 — 简明图文教程(3分钟后爽歪歪)
- fw 3.6 - stack sort- java version - 2013年12月16日23:23:32
- ALSA声卡驱动中的DAPM详解之三:如何定义各种widget
- CSS 替换元素和非替换元素
- 人人,金山西山居,腾讯互娱,微信,网易游戏offer及面经
- Android实现推送方式解决方案
- MyEclipse破解
- 把cocos2dx的游戏打包成dylib,实现动态更新
- 影片介绍
- Apache 是如何完成负载均衡策略配置