Serialize And Deserialize A Given N-Ary Tree

broken image
broken image
broken image

Call it once on the stream and it will hand you the top node with all the descendant nodes in place-the entire tree. It would read in the node itself, read in the number of child nodes, then read in each child node, if any. To deserialize, write a method that reads in a node. Now call the method on the top node in the tree and you've serialized it. It would write out the node, then write out the number of children (zero for leaf nodes), then call itself to write each child if there are any. Write a method (subroutine, function) that writes out one node and all the tree below it. Looks to me like a good use for recursion.