Coursera Algorithms week4 基础标签表 练习测验:Inorder traversal with constant extra space

Posted evasean

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Coursera Algorithms week4 基础标签表 练习测验:Inorder traversal with constant extra space相关的知识,希望对你有一定的参考价值。

题目原文:

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的主要内容,如果未能解决你的问题,请参考以下文章

text Coursera Week4编程作业2

text Coursera Week4编程作业1

Coursera TensorFlow 基础课程-week4

Coursera TensorFlow 基础课程-week4

Coursera TensorFlow 基础课程-week4

吴恩达-coursera-机器学习-week4