对于有序二进制搜索树遍历,有一种迭代算法,它不使用称为Morris Traversal的辅助内存(堆栈,父指针,访问标志)。是否有类似的预订和后序遍历算法?
答案 0 :(得分:1)
刚刚制定了预订序遍历的解决方案,可能会有效
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
如果算法出现问题,请进行评论