From: Glen Holcomb Date: 2009-02-18T23:30:18+09:00 Subject: Re: Tree structure - how do we link nodes together? --000e0cd22d52b5baa7046332422f Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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 . . . -- "Hey brother Christian with your high and mighty errand, Your actions speak so loud, I can't hear a word you're saying." -Greg Graffin (Bad Religion) --000e0cd22d52b5baa7046332422f--