首页 > 代码库 > Coursera Algorithms week4 基础标签表 练习测验:Inorder traversal with constant extra space
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。