From: Dylan Evans Date: 2009-02-19T19:06:04+09:00 Subject: Re: Tree structure - how do we link nodes together? --000e0cd1b57a0f89d2046342b0b3 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Thu, Feb 19, 2009 at 12:29 AM, Aldric Giacomoni <"aldric[removeme]"@ trevoke.net> wrote: > Dylan Evans wrote: > > [Note: parts of this message were removed to make it a legal post.] > > > > I would be inclined to use an array, part of the beauty of dynamic > languages > > is the typeless nature of arrays which does away with a lot of management > > code, in c++ trees i normally write a base node class then branch and > leaf > > nodes which is a lot of work compared to [x, [y, z]] > > Of course if you wanted to create branch nodes for some custom purpose > then > > you could just assign the children to it since they are passed by > reference. > > > > > How would .. passing the children by reference work? Is that the same > thing that Robert is talking about? > The idea of an array is simple enough that it might work.. I should be > able to write something to handle however many layers deep the arrays It's fairly common in the c/c++ world to implement tree's with arrays, a matter of preference really, or in some cases it may be quicker to access a node by it's index rather than searching through a linked list, or a pain reallocating memory. Of course i don't know what your planning so i'm just guessing, but you should be able to search with a recursive function. You may also find a hash more convenient for accessing child nodes. > > go.. But I think a tree may be a little handier to handle things like > deleting a node and its children. Check out Array#delete > > --Aldric > > -- The UNIX system has a command, nice ... in order to be nice to the other users. Nobody ever uses it." - Andrew S. Tanenbaum --000e0cd1b57a0f89d2046342b0b3--