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