Serialize a Binary Tree or a General Tree

For a binary tree, preorder traversal may be enough.

 

For example, 

    _30_
   /    \   
  10    20
 /     /  \
50    45  35
The result is 

30 10 50 # # # 20 45 # # 35 # #
Using a queue to deserialize it . 

But a for multi-way tree, we could also use an array to serialize it, e.g., 

30 10 20 50 45 35

-1   0    0   1    2   2



posted @ 2016-01-21 17:53  lcchuguo  阅读(165)  评论(0编辑  收藏  举报