1. @Test
  2. public void e1_3_5() {
  3. Stack<Integer> stack = new Stack<Integer>();
  4. int N = 7;
  5. while (N > 0) {
  6. stack.push(N % 2);
  7. N = N / 2;
  8. }
  9. for (int d : stack)
  10. StdOut.print(d);
  11. StdOut.println();
  12. }

算法Sedgewick第四版-第1章基础-012一用stack实现输出一个数的二进制形式的更多相关文章

  1. 算法Sedgewick第四版-第1章基础-014一用stack把前置表达式转为后置表达式并计算值

    1. /************************************************************************* * Exercise 1.3.10 * * ...

  2. 算法Sedgewick第四版-第1章基础-013一用stack实现自动补全表达式括号

    package algorithms.exercise; import algorithms.ADT.Stack; import algorithms.util.StdIn; import algor ...

  3. 算法Sedgewick第四版-第1章基础-001递归

    一. 方法可以调用自己(如果你对递归概念感到奇怪,请完成练习 1.1.16 到练习 1.1.22).例如,下面给出了 BinarySearch 的 rank() 方法的另一种实现.我们会经常使用递归, ...

  4. 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-001选择排序法(Selection sort)

    一.介绍 1.算法的时间和空间间复杂度 2.特点 Running time is insensitive to input. The process of finding the smallest i ...

  5. 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-007归并排序(自下而上)

    一. 1. 2. 3. 二.代码 package algorithms.mergesort22; import algorithms.util.StdIn; import algorithms.uti ...

  6. 算法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 ...

  7. 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-005插入排序的改进版

    package algorithms.elementary21; import algorithms.util.StdIn; import algorithms.util.StdOut; /***** ...

  8. 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-004希尔排序法(Shell Sort)

    一.介绍 1.希尔排序的思路:希尔排序是插入排序的改进.当输入的数据,顺序是很乱时,插入排序会产生大量的交换元素的操作,比如array[n]的最小的元素在最后,则要经过n-1次交换才能排到第一位,因为 ...

  9. 算法Sedgewick第四版-第1章基础-2.1Elementary Sortss-002插入排序法(Insertion sort)

    一.介绍 1.时间和空间复杂度 运行过程 2.特点: (1)对于已排序或接近排好的数据,速度很快 (2)对于部分排好序的输入,速度快 二.代码 package algorithms.elementar ...

随机推荐

  1. js修改隔行tr的颜色。

    <!DOCTYPE html><html lang="zh-Hans"><head> <meta charset="UTF-8& ...

  2. 轮廓Outline|表格Table实例

    1.使用outline属性在元素周围画一条线. border:red solid thin; outline:#00ff00 dotted thick; outline-style:dotted|da ...

  3. 在Java中定义常量

    方法一采用接口(Interface)的中变量默认为static final的特性. 方法二采用了Java 5.0中引入的Enum类型. 方法三采用了在普通类中使用static final修饰变量的方法 ...

  4. hdu-2544-最短路(Bellman-Ford算法模板)

    题目链接 题意很清晰,入门级题目,适合各种模板,可用dijkstra, floyd, Bellman-ford, spfa Dijkstra链接 Floyd链接 Bellman-Ford链接 SPFA ...

  5. BEC translation exercise 1

    U.S. oil drillers have made major efficiency improvements with a speed that has repeatedly surprised ...

  6. asp.net core mcroservices 架构之 分布式日志(二)之自定义日志开发

    netcore日志原理 netcore的日志是作为一个扩展库存在的,每个组件都有它的入口,那么作为研究这个组件的入口是最好的,首先看两种方式: 这个是源码例子提供的. var loggingConfi ...

  7. HUST 1010 The Minimum Length

    There is a string A. The length of A is less than 1,000,000. I rewrite it again and again. Then I go ...

  8. LeetCode 340. Longest Substring with At Most K Distinct Characters

    原题链接在这里:https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters/ 题目: Give ...

  9. [转]express 路由控制--next

    next() express的路由控制有个next()功能,在定义了多个路由的时候,对匹配的url会按顺序执行, 例如,有这样两个路由,第一个路由会对满足“/”的地址,在req中添加一个user的属性 ...

  10. 4、运行成功的Demo(PyCharm+Selenium)

    1.打开PyCharm,新建一个python.file,输入代码“from selenium import webdriver”报错的解决方法 (1)PyCharm没有找到正确的python,在“Fi ...