对于中序二叉搜索树遍历,有一种迭代算法不使用辅助内存(堆栈、父指针、已访问标志),称为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++ - 无需额外存储的二叉搜索树迭代前序遍历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25763218/