题目原文:

Design an algorithm to perform an inorder traversal of a binary search tree using only a constant amount of extra space.

  1. public void traverse(BST<Key,Value> bst) {
  2. traverse(bst.root.left, bst.root);
  3. }
  4.  
  5. private void traverse(Node current, Node parent) {
  6. while (current != null) {
  7. if (parent != null) {
  8. parent.left = current.right;
  9. current.right = parent;
  10. }
  11. if (current.left != null) {
  12. parent = current;
  13. current = current.left;
  14. } else {
  15. System.out.println(current.key);
  16. current = current.right;
  17. parent = null;
  18. }
  19. }
  20. }

Coursera Algorithms week4 基础标签表 练习测验:Inorder traversal with constant extra space的更多相关文章

  1. Coursera Algorithms week4 基础标签表 练习测验:Check if a binary tree is a BST

    题目原文: Given a binary tree where each 

  2. Coursera Algorithms week4 基础标签表 练习测验:Java autoboxing and equals

    1. Java autoboxing and equals(). Consider two double values a and b and their corresponding Double v ...

  3. Coursera Algorithms week2 基础排序 练习测验: Dutch national flag 荷兰国旗问题算法

    第二周课程的Elementray Sorts部分练习测验Interview Questions的第3题荷兰国旗问题很有意思.题目的原文描述如下: Dutch national flag. Given ...

  4. Coursera Algorithms week2 基础排序 练习测验: Permutation

    题目原文: Given two integer arrays of size n , design a subquadratic algorithm to determine whether one ...

  5. Coursera Algorithms week2 基础排序 练习测验: Intersection of two sets

    题目原文: Given two arrays a[] and b[], each containing n distinct 2D points in the plane, design a subq ...

  6. Coursera Algorithms week2 栈和队列 练习测验: Stack with max

    题目原文: Stack with max. Create a data structure that efficiently supports the stack operations (push a ...

  7. Coursera Algorithms week2 栈和队列 练习测验: Queue with two stacks

    题目原文: Implement a queue with two stacks so that each queue operations takes a constant amortized num ...

  8. [06]HTML基础之表单标签

    1. <form>标签 表单容器,指定method属性和action属性是个良好的习惯. <form methor="POST" action="htt ...

  9. Bootstrap<基础六> 表单

    Bootstrap 通过一些简单的 HTML 标签和扩展的类即可创建出不同样式的表单. 表单布局 Bootstrap 提供了下列类型的表单布局: 垂直表单(默认) 内联表单 水平表单 垂直或基本表单 ...

随机推荐

  1. 二叉查找树(Binary Search Tree)

    Date:2019-06-25 14:40:32 基本操作 注意:数据量较大时,插入建树的时间复杂度会很高,慎用! //查找 void Search(node *root, int x) { if(r ...

  2. 数据结构---链表ADT C++实现

    最近在学习数据结构,刚开始一直在看书,但是总是感觉似懂非懂,心想还不如自己操练一波,势必有所收获.现将实现代码发表此地,以备日后复习,若有错误或者建议,欢迎告知本人! 1. 节点类 class Nod ...

  3. AWK简单使用方法

    1. 命令格式 gawk [OPTIONS] 'program' FILES.... program:'PATTERN{ACTION}' 一条awk命令中,PATTERN和ACTION,至少存在一个才 ...

  4. 51nod1128 正整数分组V2

    [题解] 二分一个最大值,check一下分出来的组数是否小于等于k即可. #include<cstdio> #include<algorithm> #define LL lon ...

  5. Billboard (HDU 2795)

    Billboard (HDU 2795) Hdu 2795 注意到每个广告的长度是1,因此可以将每这一张广告牌当成一个数列表示,每个初始值为w.使用线段树维护这个数列,每次查询为找到这个数列第一个大于 ...

  6. java属性的默认值

    String 默认null Boolean默认false int默认0 double默认0.0 类中使用自定义类定义属性默认值:null 在定义属性的时候可以指定默认值

  7. 关于构造函数及参数执行顺序说明(c#)

    原文:https://blog.csdn.net/junmail/article/details/83249186 构造函数的执行顺序: 子类静态变量>子类静态构造函数>子类非静态变量&g ...

  8. Maven学习总结(29)——Maven项目的pom.xml中log4j2配置

        <dependency>         <groupId>org.apache.logging.log4j</groupId>         <a ...

  9. 对jetbrains全系列可用例:IDEA、WebStorm、phpstorm、clion等----https://blog.csdn.net/u014044812/article/details/78727496

    https://blog.csdn.net/u014044812/article/details/78727496 pyCharm最新2018激活码

  10. Leetcode 92.反转链表

    92.反转链表 反转从位置 m 到 n 的链表.请使用一趟扫描完成反转. 说明:1 ≤ m ≤ n ≤ 链表长度. 示例: 输入: 1->2->3->4->5->NULL ...