From: Aldric Giacomoni <"aldric[remove]"@...> Date: 2009-02-19T23:24:53+09:00 Subject: Re: Tree structure - how do we link nodes together? Glen Holcomb wrote: > [Note: parts of this message were removed to make it a legal post.] > > On Wed, Feb 18, 2009 at 7:20 AM, Aldric Giacomoni <"aldric[removeme]"@ > trevoke.net> wrote: > > >> Robert Klemme wrote: >> >>> 2009/2/18 Aldric Giacomoni <"aldric[removeme]"@trevoke.net>: >>> >>> >>>> I know I could just use rubytree, which looks quite nice, but I'd like >>>> to see what you guys would do about creating a tree and linking the >>>> nodes together. >>>> In C++ we'd just make pointers, so how would we do the equivalent in >>>> >> Ruby? >> >>> We use object references - as always when referring other objects. >>> Ruby does not have the multitude of options that C++ has. >>> >>> Cheers >>> >>> robert >>> >>> >>> >>> >> Alright, Robert - I don't know how that works in Ruby! Would you provide >> me with a simple example, explain it, or point me to something that >> explains it, please? >> >> Thanks, >> >> --Aldric >> >> >> > Pretty Simple really: > > class Node > attr_accessor :data > attr_accessor :left > attr_accessor :right > end > > root = Node.new > > node1 = Node.new > > root.data = "rob" > node1.data = "tim" > root.right = node1 > > Oh - DUH ! Thanks. Clearly I wasn't thinking straight. --Aldric