aboutsummaryrefslogtreecommitdiff
path: root/challenge-113
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-05-19 11:59:29 +0100
committerdrbaggy <js5@sanger.ac.uk>2021-05-19 11:59:29 +0100
commit679dc509ad21abb1f6d2365330639b3f40fc7c69 (patch)
tree1b24d7b3e7f151403388a6c2757e2d63ce72c2ef /challenge-113
parentd8828a6cfbadb2f453508a4390777534ab4e5dca (diff)
downloadperlweeklychallenge-club-679dc509ad21abb1f6d2365330639b3f40fc7c69.tar.gz
perlweeklychallenge-club-679dc509ad21abb1f6d2365330639b3f40fc7c69.tar.bz2
perlweeklychallenge-club-679dc509ad21abb1f6d2365330639b3f40fc7c69.zip
just tidying
Diffstat (limited to 'challenge-113')
-rw-r--r--challenge-113/james-smith/perl/ch-2.pl27
1 files changed, 19 insertions, 8 deletions
diff --git a/challenge-113/james-smith/perl/ch-2.pl b/challenge-113/james-smith/perl/ch-2.pl
index 47c2f4c84e..53a05bf5d7 100644
--- a/challenge-113/james-smith/perl/ch-2.pl
+++ b/challenge-113/james-smith/perl/ch-2.pl
@@ -36,6 +36,8 @@ $x->walk( sub { my( $node, $global, $local ) = @_;
$global->{'tree'} = Tree->new( $node->[0] );
return $global->{'tree'};
}, $clone );
+say;
+say 'Original tree code';
my $y = $clone->{'tree'};
say '';
@@ -57,13 +59,18 @@ is( "@{[ $x->flatten ]}", '1 2 4 7 3 5 6' );
is( "@{[ $y->flatten ]}", '27 26 24 21 25 23 22' );
say '';
-$x = BinaryTree->new(1)->add_child_left(
- BinaryTree->new(2)->add_child_left(
- BinaryTree->new(4)->add_child_right( BinaryTree->new(7) )
- )
- )->add_child_right(
- BinaryTree->new(3)->add_child_left( BinaryTree->new(5))->add_child_right( BinaryTree->new(6) )
- );
+$x = BinaryTree->new(1)
+ ->add_child_left(
+ BinaryTree->new(2)
+ ->add_child_left(
+ BinaryTree->new(4)
+ ->add_child_right( BinaryTree->new(7) )
+ )
+ )->add_child_right(
+ BinaryTree->new(3)
+ ->add_child_left( BinaryTree->new(5) )
+ ->add_child_right( BinaryTree->new(6) )
+ );
## Generate clone of $x, and compute the total of all the nodes...
@@ -76,8 +83,12 @@ $x = BinaryTree->new(1)->add_child_left(
$y;
+say '
+Now using the binary specific code - with clone/dump/flatten methods
+added into the class implemented by walk
+
+';
-say '';
say 'Dump $x';
$x->dump( sub { "[$_[0]]"; } );
say '';