首页 文章

二进制搜索树迭代前序遍历,无需额外存储

提问于
浏览
1

对于顺序二进制搜索树遍历,存在一种迭代算法,其不使用称为Morris Traversal的辅助存储器(堆栈,父指针,访问标志) . 是否有类似的预订和后序遍历算法?

1 回答

  • 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
    

    如果算法出现问题,请发表评论

相关问题