From: ahoward Date: 2002-10-30T05:35:28+09:00 Subject: Re: problem with recursive structure On Wed, 30 Oct 2002, Mark Probert wrote: > > Dear Rubists, > > I have a little class called SimpleTree that makes a recursive > data structure of arrays. I am getting some funny behaviour when > I traverse the tree for printing. > > The print routine is: > > def pp_branch(b) > puts "(head) #{b[0]}" > b.each { |item| > next if item == b[0] # avoid the head > pp_branch(item) if item.type == Array > puts "(leaf) #{item}" > } > end try this: def pp_branch(b) puts "(head) #{b[0]}" b.each { |item| next if item == b[0] # avoid the head if item.type == Array pp_branch(item) else puts "(leaf) #{item}" end } end looks like you are BOTH recursing on Array types AND printing them as leaves. have you seen the RBTree from RAA? it's fast. -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================