簡體   English   中英

二進制搜索樹迭代式遍歷遍歷,無需額外存儲

[英]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

如果算法有問題,請發表評論

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM