Serialize, deserialize tree

By | August 3, 2015
Share the joy
  •  
  •  
  •  
  •  
  •  
  •  

Given a tree structure, serialize it, and deserialize it. One of the way to do it, is to store the number of children in the serializing. Take below tree as an example:

The serializing result will be:

The red ones are the number of children information. And use queue to implement it.

Check my code on github.