christopher j bottaro wrote:

> just for practice, i made a class BinaryTree.  its just a blessed reference to
> a hash that contains two things:  size and root.  root gets assigned to a
> BinaryTree::Node which is just a bless reference containing: key, value,
> left, right.
>
> perl deallocates according to reference counts.  so if i want "destory" my
> tree structure, i'd have to make sure there are no references to any of the
> BinaryTree::Node's, right?

Nope.  Try
$root = undef;



> something like this...
>
> $my pr_clear;
> $pr_clear = sub {
>         my $p = shift(); # parent node
>         my $w = shift(); # which child of the parent
>         my $n = shift(); # child node
>         if ($n != undef)        {
>                 this->$pr_clear($n, "left", $n->left());
>                 this->$pr_clear($n, "right", $n->right());
>                 $p->$w(undef);
>         }
> }
>
> sub clear()     {
>         this->$pr_clear(this->{root}, "left", this->{root}->left());
>         this->$pr_clear(this->{root}, "right", this->{root}->right());
>         this->{root} = undef;
> }
>
> thanks in advance, and thanks to those who helped with the module questions,
> -- christopher

Looks like a good structure for doing the chore in C++, though.

Joseph



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to