diff options
| author | drbaggy <js5@sanger.ac.uk> | 2021-08-09 15:46:59 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2021-08-09 15:46:59 +0100 |
| commit | 6fddb13683f2f163aa9a83ea21230b1a07cc7fcf (patch) | |
| tree | ad76b8e1cd5991d6f5570bb4d4248a7a15f0136c | |
| parent | a33edce979ce6b299a1df1640a83dc67231a14bd (diff) | |
| download | perlweeklychallenge-club-6fddb13683f2f163aa9a83ea21230b1a07cc7fcf.tar.gz perlweeklychallenge-club-6fddb13683f2f163aa9a83ea21230b1a07cc7fcf.tar.bz2 perlweeklychallenge-club-6fddb13683f2f163aa9a83ea21230b1a07cc7fcf.zip | |
there is one more thing I've got to add as I don't think 2 is done exhaustively enough yet...
| -rw-r--r-- | challenge-125/james-smith/perl/ch-2.pl | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/challenge-125/james-smith/perl/ch-2.pl b/challenge-125/james-smith/perl/ch-2.pl index 451047c0cb..d4d2cb738d 100644 --- a/challenge-125/james-smith/perl/ch-2.pl +++ b/challenge-125/james-smith/perl/ch-2.pl @@ -26,6 +26,7 @@ my $x = BinaryTree->new(1)->add_child_left( BinaryTree->new(5)->add_child_left( BinaryTree->new(6))->add_child_right( BinaryTree->new(7)->add_child_left( BinaryTree->new(8)->add_child_left(BinaryTree->new(9)) )->add_child_right(BinaryTree->new(10)) )); +say '1) Tree with root node having both left and right children!'; $x->dump; say sprintf 'Max depth: %d, diameter %d', $x->depth, $x->diameter; say ''; @@ -43,6 +44,7 @@ $x = BinaryTree->new(1)->add_child_left( BinaryTree->new(7) )))))); +say '2) Tree with no node having two children'; $x->dump; say sprintf 'Max depth: %d, diameter %d', $x->depth, $x->diameter; say ''; @@ -64,6 +66,8 @@ $x = BinaryTree->new(1)->add_child_left( ) ))); +say '3) Tree with node further down having two children - but distance from'; +say ' root to node is greater than the depth of either child'; $x->dump; say sprintf 'Max depth: %d, diameter %d', $x->depth, $x->diameter; say ''; @@ -76,6 +80,8 @@ say ''; ## --------------------- ## 6 -> 5 -> 2 -> 3 -> 4 [ diameter 5 ] +say '4) Tree with node further down having two children - but distance from'; +say ' root to node is less than the depth of both children'; $x = BinaryTree->new(1)->add_child_left( BinaryTree->new(2)->add_child_left( BinaryTree->new(3)->add_child_left( BinaryTree->new(4) ) |
