History of Idiom 9 > diff from v38 to v39
Edit summary for version 39 by daxim:
New Perl implementation by user [daxim]
New Perl implementation by user [daxim]
↷
Version 38
2019-09-27, 03:58:30
Version 39
2019-09-27, 07:45:57
Idiom #9 Create a Binary Tree data structure
The structure must be recursive because left child and right child are binary trees too. A node has access to children nodes, but not to its parent.
Idiom #9 Create a Binary Tree data structure
The structure must be recursive because left child and right child are binary trees too. A node has access to children nodes, but not to its parent.
Code
class Tree::Binary {
has 'left', is => 'ro', isa => Maybe[InstanceOf['Tree::Binary']];
has 'right', is => 'ro', isa => Maybe[InstanceOf['Tree::Binary']];
has 'val', is => 'ro', isa => Int;
}
my $t = Tree::Binary->new(
val => 42,
left => Tree::Binary->new(val => 23),
right => Tree::Binary->new(
val => 1729,
right => Tree::Binary->new(val => -1)
)
);
__END__
42
↙ ↘
23 1729
↙ ↘ ↙ ↘
∅ ∅ ∅ -1