首页 > 其他 > 详细

Morris post order traversal algorithm

时间:2015-09-14 07:02:40      阅读:232      评论:0      收藏:0      [点我收藏+]
Sept. 5, 2015

花时间把代码读明白, 比光看书强. 动手写代码, 改代码,  
兴趣是最好的老师. 多记几个例子, 增加情趣. 

举个例子关于中序遍历, 
           4
        /     \
       2       6
     /  \     / \
    1   3   5   7 
easy way to travel is to remember the order of its position in the horizontal way 
 
       
 技术分享

 

 

现在, 要做Morris 的后序遍历, 有一个技巧, 是在我写完这个C#代码才发现的, 
 
                     
                  9
                /    \
               5      8
              / \       \
             1   4     7
                  / \   /
                2   3 6
就是从最左边开始, 遍历五次, 
 
 1, 
 2, 
 3, 4, 5 
 6, 
 7, 8, 9, 
 
 
最后结果是 1 2 3 4 5 6 7 8 9 
加一个dummy node, with left child is the root node.  

 

Morris post order traversal algorithm

原文:http://www.cnblogs.com/juliachenOnSoftware/p/4806102.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!