The list
t1 = {1, 2, 3, 3, 4, 4, 3, 3, 4, 3, 3, 2, 3, 4, 2, 3, 2}; might be derived from a pre-order traversal of
tree1 = Tree[1, {Tree[2, {3, Tree[3, {4, 4}], 3, Tree[3, {4}], 3, 3}], Tree[2, {Tree[3, {4}]}], Tree[2, {3}], 2}] But how to take the original list, t1 here, and build the tree tree1 ?
What have I tried so far ? Nothing to any avail! Well, that's not quite true, I have made some progress with a very procedural code to walk along the list and try to figure out the structure of the tree as each new element is read, but I have a dispiriting feeling that I have missed an obvious usage of some of the smarter functional programming functionality.






Tree[4, {}]could not occur? $\endgroup$Tree[n,{}]shouldn't occur, that would just be a leaf at leveln.Treelooks quite neat and I'm trying to figure out how to use it to replace a lot of old code I have which uses the existing Graph type for manipulating what are really Trees. $\endgroup$TreeFormhas been around so long, it's about time something likeTreehas surfaced at the user level. $\endgroup$