[英]Binary search tree iterative preorder traversal without additional storage
剛剛想出了遍歷遍歷的解決方案,可能會奏效
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.