On Feb 12, 2006, at 8:38 PM, frank wrote: > For example, take the following tree: > > ((A,B),C) > > Where ( represents a node, each letter represents a leaf. I am > currently using a very clunky set of arrays to hold all the > information. > > leaf = Array.new > node = Array.new > left = Array.new #represents the child to the left > right = Array.new #represents the child to the right > parent = Array.new > > I number each element in the array based on moving up the tree and > reading either a left or right node or leaf. > left = i*2 > right = i*2+1 Is there any reason not to use a simpler approach (my opinion), like: [ ["A", "B"], "C" ] ? Seems like traversing that with first(), last(), and is_a?(Array) ought to be pretty simple. You can wrap it in a class to make it even easier. > Using the above tree and information in the array elements, I want to > be able to duplicate portions of the tree, such that I could get > something like: > > (((A,B),(A,B)), C) branch = ["A", "B"] [ branch, branch, "C" ] ? James Edward Gray II