相关疑难解决方法(0)

在不使用堆栈或递归的情况下解释Morris inorder树遍历

有人可以帮我理解下面的Morris inorder树遍历算法而不使用堆栈或递归吗?我试图了解它是如何工作的,但它只是逃避了我.

 1. Initialize current as root
 2. While current is not NULL
  If current does not have left child     
   a. Print current’s data
   b. Go to the right, i.e., current = current->right
  Else
   a. In current's left subtree, make current the right child of the rightmost node
   b. Go to this left child, i.e., current = current->left
Run Code Online (Sandbox Code Playgroud)

我理解的树被修改的方式,将current node在作出right child的的max noderight subtree和使用该财产序遍历.但除此之外,我迷失了.

编辑:找到这个附带的c ++代码.我很难理解修改后树的恢复方式.神奇在于else子句,一旦修改了正确的叶子就会被击中.请参阅代码了解详情:

/* Function to traverse binary …
Run Code Online (Sandbox Code Playgroud)

c++ binary-tree tree-traversal

101
推荐指数
4
解决办法
3万
查看次数

标签 统计

binary-tree ×1

c++ ×1

tree-traversal ×1