二进制搜索树迭代预序遍历,无需额外存储
Binary search tree iterative preorder traversal without additional storage
对于有序的二进制搜索树遍历,有一种不使用辅助内存(堆栈、父指针、访问标志)的迭代算法,称为Morris traversal。对于预订单和后订单遍历,有类似的算法吗?
刚刚为预购遍历找到了一个解决方案,可能可以使用
Initialize current as root
While current is not NULL
If current does not have right child
a) print current root
b) Go to the left, i.e., current = current->left
Else
a) print current root
a) Make the whole right sub-tree of current as the left node of the rightmost child in the left sub tree(inorder predecessor of current)
b) Go to the left child, i.e., current = current->left
如果算法有问题,请发表评论
相关文章:
- 有什么方法可以遍历结构吗
- 在循环中按顺序遍历成员变量
- 遍历模板参数
- 在遍历处理程序的向量时注册和注销处理程序
- C++RapidXml-使用first_node()遍历以修改XML文件中节点的值
- 遍历并行数组以确定C++中的最大数字
- 遍历顺序由 std::文件系统directory_iterator给出
- 遍历链表时的无限循环
- 遍历unordered_map向量
- 从预序遍历构造 bst 的 c++ 和 python 解决方案之间的区别
- C++声明双链表,使用两个 for 循环双向遍历列表并打印
- 如何正确地推回然后遍历堆中对象的向量?
- 遍历二维数组的所有子数组
- 如何在可变参数模板函数中遍历可变参数元组?
- 避免在遍历 IShellItemArray 时出现代码重复
- 从特定键开始遍历地图
- C/C++ 三维数组如何在内存中存储,以及遍历它的最快方法是什么
- 如何遍历当前目录并将文件存储在数组中?Bash 外壳脚本
- 二进制搜索树迭代预序遍历,无需额外存储
- 设计数据结构来存储多键对象集,以便能够收集和遍历该集的超平面