烙饼排序问题
来源:互联网 发布:商标注册号是什么淘宝 编辑:程序博客网 时间:2024/04/27 18:14
在这里我只给出最普通的一种方法,其他最优的请自行考虑:
import java.util.*;public class BianChengZhiMei {public static void main(String args[]){int[] st = {3,2,1,6,5,4,9,8,5,7,0,15,25,10,66,24,25,20,99,70};st=sort_bing(st,st.length);System.out.print("最终结果: ");for(int i=0;i<st.length;i++){System.out.print(st[i]+" ");}}public static int[] sort_bing(int[] array,int n){System.out.print("第"+(array.length-n)+"次翻饼过程: ");for(int i=0;i<array.length;i++){System.out.print(array[i]+" ");}System.out.println();Stack<Integer> stack = new Stack<Integer>();int[] arry = array;int max=arry[0],j=0,k =n;if(n==1)return arry;for(int i=0;i<k;i++){if(max<=arry[i]){max = arry[i];j=i;}}for(int i=0;i<=j;i++){stack.push(arry[i]);}for(int i=0;i<=j;i++){arry[i]=stack.pop();}for(int i=0;i<k;i++){stack.push(arry[i]);}for(int i=0;i<k;i++){arry[i]=stack.pop();}return sort_bing(arry,k-1);}}结果如下:
第0次翻饼过程: 3 2 1 6 5 4 9 8 5 7 0 15 25 10 66 24 25 20 99 70
第1次翻饼过程: 70 3 2 1 6 5 4 9 8 5 7 0 15 25 10 66 24 25 20 99
第2次翻饼过程: 20 25 24 66 10 25 15 0 7 5 8 9 4 5 6 1 2 3 70 99
第3次翻饼过程: 3 2 1 6 5 4 9 8 5 7 0 15 25 10 20 25 24 66 70 99
第4次翻饼过程: 24 3 2 1 6 5 4 9 8 5 7 0 15 25 10 20 25 66 70 99
第5次翻饼过程: 20 10 24 3 2 1 6 5 4 9 8 5 7 0 15 25 25 66 70 99
第6次翻饼过程: 15 0 7 5 8 9 4 5 6 1 2 3 20 10 24 25 25 66 70 99
第7次翻饼过程: 10 15 0 7 5 8 9 4 5 6 1 2 3 20 24 25 25 66 70 99
第8次翻饼过程: 3 2 1 6 5 4 9 8 5 7 0 10 15 20 24 25 25 66 70 99
第9次翻饼过程: 3 2 1 6 5 4 9 8 5 7 0 10 15 20 24 25 25 66 70 99
第10次翻饼过程: 0 7 5 8 3 2 1 6 5 4 9 10 15 20 24 25 25 66 70 99
第11次翻饼过程: 4 5 6 1 2 3 0 7 5 8 9 10 15 20 24 25 25 66 70 99
第12次翻饼过程: 5 4 5 6 1 2 3 0 7 8 9 10 15 20 24 25 25 66 70 99
第13次翻饼过程: 0 3 2 1 5 4 5 6 7 8 9 10 15 20 24 25 25 66 70 99
第14次翻饼过程: 0 3 2 1 5 4 5 6 7 8 9 10 15 20 24 25 25 66 70 99
第15次翻饼过程: 4 0 3 2 1 5 5 6 7 8 9 10 15 20 24 25 25 66 70 99
第16次翻饼过程: 1 2 3 0 4 5 5 6 7 8 9 10 15 20 24 25 25 66 70 99
第17次翻饼过程: 0 1 2 3 4 5 5 6 7 8 9 10 15 20 24 25 25 66 70 99
第18次翻饼过程: 0 1 2 3 4 5 5 6 7 8 9 10 15 20 24 25 25 66 70 99
第19次翻饼过程: 0 1 2 3 4 5 5 6 7 8 9 10 15 20 24 25 25 66 70 99
最终结果: 0 1 2 3 4 5 5 6 7 8 9 10 15 20 24 25 25 66 70 99
- 烙饼排序问题
- 烙饼排序
- 烙饼排序
- 烙饼排序
- 编程之美-- 烙饼排序问题
- 关于烙饼排序问题的优化
- 编程之美-- 烙饼排序问题
- 排序问题——翻转烙饼
- 编程之美 - 读书笔记 - 一摞烙饼的排序问题
- 编程之美 一摞烙饼的排序问题
- 《编程之美》烙饼排序问题的简单实现
- 《编程之美》之摞烙饼的排序问题
- 一摞烙饼的排序问题--读书笔记(2)
- 编程之美——烙饼排序问题
- 关于烙饼排序问题的算法与Java实现
- 烙饼排序的实现
- 【算法C++】烙饼排序
- 【经典算法】:烙饼排序
- git中rejected的解决方法
- 在页面添加编译信息
- 【Linux】在Ubuntu中布置LAMP环境
- Android事件分发
- Java程序执行Linux命令
- 烙饼排序问题
- MyISAM和InnoDB的区别
- ssh: connect to host localhost port 22: Connection refused : 通过系统日志排查问题
- NYOJ-【士兵杀敌(二)】
- POJ 1845 Sumdiv(逆元+快速幂)
- sublime使用xdebug调试php
- shell 脚本功能汇总
- 批量读取数据文件以及提取字符串中的数字-R语言
- Archlinux下安装docker