题目原文:

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

 public void traverse(BST<Key,Value> bst) {
traverse(bst.root.left, bst.root);
} private void traverse(Node current, Node parent) {
while (current != null) {
if (parent != null) {
parent.left = current.right;
current.right = parent;
}
if (current.left != null) {
parent = current;
current = current.left;
} else {
System.out.println(current.key);
current = current.right;
parent = null;
}
}
}

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. 【原】Mysql存储关联数组

    $fruits= array("apple" => "苹果", "banana" => "香蕉"," ...

  2. Python之UDP编程

    参考原文 廖雪峰Python教程 TCP是建立可靠连接,并且通信双方都可以以流的形式发送数据.相对TCP,UDP则是面向无连接的协议. 使用UDP协议时,不需要建立连接,只需要知道对方的IP地址和端口 ...

  3. React-native SyntaxError: Unexpected token ...

    更新 node.js 版本到  v6.11.1. https://github.com/facebook/react-native/issues/15040

  4. config对象的使用及常用方法

    config对象的使用及常用方法 制作人:全心全意 config对象主要用于取得服务器的配置信息.通过pageContext对象的getServletConfig()方法可以获取一个config对象. ...

  5. 团队一致性的PHP开发环境之Vagrant

    Vagrant 简介 Vagrant是一个基于Ruby的工具,用于创建和部署虚拟化开发环境. 它的主要意义是让所有开发人员都使用和线上服务器一样的环境,本质上和你新建一个虚拟机 安装 # https: ...

  6. oldboy python 3.5 week 1

    #!/usr/bin/env python # -*- coding:utf-8 -*- ------------------------------------------- name = inpu ...

  7. 第八节:web爬虫之urllib(四)

    第三个 模块parse : 是一个工具模块,提供了许多 URL 处理方法,比如拆分.解析.合并等等的方法.

  8. 洛谷 2449 [SDOI2005]矩形

    [题解] 因为这道题中n比较小,n^2效率是可以接受的. 枚举两个矩形,如果它们有重叠部分,就用并查集合并一下即可. #include<cstdio> #include<algori ...

  9. Uva1103 Ancient Messages

    题意:识别图中的象形文字.但是,图形可以任意的拉伸,但不能拉断. 分析:这种题如果图形没有特征是不可做类型的题,不过观察图形可以发现每个图形中的洞的数量是一定的,我们只需要数出每一个封闭图形的洞数就能 ...

  10. UVa - 12617 - How Lader

    先上题目:   How Lader  Lader is a game that is played in a regular hexagonal board (all sides equal, all ...