码迷,mamicode.com
首页 > 其他好文 > 详细

Serialize a Binary Tree or a General Tree

时间:2014-11-03 16:28:42      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:des   style   color   ar   for   sp   on   bs   amp   

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



Serialize a Binary Tree or a General Tree

标签:des   style   color   ar   for   sp   on   bs   amp   

原文地址:http://blog.csdn.net/taoqick/article/details/40741433

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!