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
blogs to read:
http://www.cnblogs.com/AnnieKim/archive/2013/06/15/MorrisTraversal.html
C# implementation:
https://github.com/jianminchen/MorrisOrder/blob/master/MorrisPostOrder.cs
Morris order in order traversal
https://github.com/jianminchen/MorrisInOrderTraverse/blob/master/Program.cs
时间: 2024-12-19 10:02:15