"just" looked at Bob's work, acts_as_threaded. I am fairly certain it is exactly what you are after. http://www.railtie.net/articles/2006/02/05/rails-acts_as_threaded-plugin -Nb ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Nathaniel S. H. Brown http://nshb.net ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > -----Original Message----- > From: frank [mailto:mjzanis / yahoo.com] > Sent: February 12, 2006 6:38 PM > To: ruby-talk ML > Subject: tree structures > > Hi, > > I have been using ruby for a few months now and am writing a > program that duplicates portions of a tree structure. > > 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 > > thus node[2] represents the node subtending the edges > leading to the left child A and the right child B. > > So to traverse this tree > ( = node 1 > ( = move up a node to 2 > A = move up to left leaf 4 > , = move down to node 2 > B = move up to the right leaf 5 > ) = move down to node 2 > , = move down to node 1 > C = move up to right child 3 > ) = move down to node 1 and end of tree > > 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) > > So moving up from node 1 to node 2 I have a duplication in A > and B. I can indicate where I have duplications but > ultimately need to write this back out into the parenthetical > notation that I am using to describe a tree. I am afraid > that I should be using struct or they may be a better way to > describe my tree structures rather than using numbered and > linked lists. Any information on using struct in ruby or > pointer equivalents would be appreciated. I am trying to > come up with a way of doing this such that I could use it on > trees of any size. > Right now I am using arrays and the bookkeeping is getting tricky. > > Thanks for any help! > frank > >