There are different types of binary trees with different rules that can help simplify deserialization, but basically just walk through the tree and output each node in order, then recreate it, read it in your file and restore the structure.
It may be useful to include markers for each node that indicate whether it is a leaf of the node (which then tells you whether the next element is lower or higher than the current node). Alternatively, you may need to have a marker that indicates a NULL node, which can help, for example, for nodes with a left but not a right branch.
EG:
A BC DEF
May be submitted:
ABD - - E - - C - F - -
Or how:
A[B[D,E],C[-,F]]
Reminds me of the computer science homework I did in college.
source share