From 6fddb13683f2f163aa9a83ea21230b1a07cc7fcf Mon Sep 17 00:00:00 2001 From: drbaggy Date: Mon, 9 Aug 2021 15:46:59 +0100 Subject: there is one more thing I've got to add as I don't think 2 is done exhaustively enough yet... --- challenge-125/james-smith/perl/ch-2.pl | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'challenge-125') 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) ) -- cgit