算法Sedgewick第四版-第1章基础-012一用stack实现输出一个数的二进制形式
@Test
public void e1_3_5() {
Stack<Integer> stack = new Stack<Integer>();
int N = 7;
while (N > 0) {
stack.push(N % 2);
N = N / 2;
}
for (int d : stack)
StdOut.print(d);
StdOut.println();
}
算法Sedgewick第四版-第1章基础-012一用stack实现输出一个数的二进制形式的更多相关文章
- 算法Sedgewick第四版-第1章基础-014一用stack把前置表达式转为后置表达式并计算值
1. /************************************************************************* * Exercise 1.3.10 * * ...
- 算法Sedgewick第四版-第1章基础-013一用stack实现自动补全表达式括号
package algorithms.exercise; import algorithms.ADT.Stack; import algorithms.util.StdIn; import algor ...
- 算法Sedgewick第四版-第1章基础-001递归
一. 方法可以调用自己(如果你对递归概念感到奇怪,请完成练习 1.1.16 到练习 1.1.22).例如,下面给出了 BinarySearch 的 rank() 方法的另一种实现.我们会经常使用递归, ...
- 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-001选择排序法(Selection sort)
一.介绍 1.算法的时间和空间间复杂度 2.特点 Running time is insensitive to input. The process of finding the smallest i ...
- 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-007归并排序(自下而上)
一. 1. 2. 3. 二.代码 package algorithms.mergesort22; import algorithms.util.StdIn; import algorithms.uti ...
- 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-006归并排序(Mergesort)
一. 1.特点 (1)merge-sort : to sort an array, divide it into two halves, sort the two halves (recursivel ...
- 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-005插入排序的改进版
package algorithms.elementary21; import algorithms.util.StdIn; import algorithms.util.StdOut; /***** ...
- 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-004希尔排序法(Shell Sort)
一.介绍 1.希尔排序的思路:希尔排序是插入排序的改进.当输入的数据,顺序是很乱时,插入排序会产生大量的交换元素的操作,比如array[n]的最小的元素在最后,则要经过n-1次交换才能排到第一位,因为 ...
- 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-002插入排序法(Insertion sort)
一.介绍 1.时间和空间复杂度 运行过程 2.特点: (1)对于已排序或接近排好的数据,速度很快 (2)对于部分排好序的输入,速度快 二.代码 package algorithms.elementar ...
随机推荐
- 制作导航菜单分隔线的总结:用css3
经过百度统计中国中使用谷歌浏览器比较多,我很奇怪,我身边的同事很少用谷歌,唯一我用谷歌的原因就是看上它调试能力和模拟手机. 下面是我个人制作的 预览用谷歌浏览器. <!doctype html& ...
- mysql ORM框架及SQLAlchemy
一 介绍 SQLAlchemy是Python编程语言下的一款ORM框架,该框架建立在数据库API之上,使用关系对象映射进行数据库操作,简言之便是:将对象转换成SQL,然后使用数据API执行SQL并获取 ...
- 手动安装mysql-5.0.45.tar.gz
Linux下编译安装 安装环境:VMware9(桥接模式) + Linux bogon 2.6.32-642.3.1.el6.x86_64(查看linux版本信息:uname -a) 先给出MySQL ...
- uva11991(二分查找或map的应用)
11991 - Easy Problem from Rujia Liu? Time limit: 1.000 seconds Easy Problem from Rujia Liu? Though R ...
- IEflash遇到flash遮挡
遇到IE中(包括IE6+)弹窗广告要flash遮挡的问题,后来想到了常用的iframe方法(参见<解决IE6 select z-index无效,遮挡div的bug>),最终成功了flash ...
- Two Cakes
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has boug ...
- LeetCode 336. Palindrome Pairs
原题链接在这里:https://leetcode.com/problems/palindrome-pairs/ 题目: Given a list of unique words, find all p ...
- 自编jQuery插件实现模拟alert和confirm
现在绝大多数网站都不用自带的alert和confirm了,因为界面太生硬了.因此这个插件就这样产生了自己定制一个的想法...... 啥也不说,先上图,有图有真相 :) 现在绝大多数网站都不用自带的al ...
- 前端优化规范 webApp
- ExtJs中获得当前选中行号(Grid中多选或者是单选)及Grid的反选(取消选中行)
多选,如何获得每行的行号: function getlineNum(){ var sm=titleGird.getSelectionModel(); // 获得grid的SelectionMod ...