in reply to List of Children Objects
Untested and (in part) schematic code follows:
sub new { my $class = shift; my $self = { children => [] }; bless $self, $class; } sub addSubBlock # (newblock) { my $self = shift; my $block = shift; push @{$self->{children}}, $block; } sub traverse_preorder { my $self = shift; my @children = (); foreach my $child (@{$self->{children}) { push @children, $child, $child->traverse_preorder; } return @children; }
OK, so I'm using a hash reference for the object data. I'm only using that for ease of illustration.
Updated:renamed traverse_inorder to traverse_preorder. D'oh!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: List of Children Objects
by PhosphoricX (Sexton) on Mar 30, 2004 at 13:17 UTC |