exercism-perl5

Repository for my Perl 5 Exercism exercises
git clone git://git.samirparikh.com/exercism-perl5
Log | Files | Refs | README

commit a88c3a1888a9e6f656dbcf5fb2450fa36b08e520
parent 25b47bc24f0bb587ebb0a986d2a1f77dc9f058ee
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Wed,  5 Jan 2022 20:10:49 +0000

get all tests, including sort, to pass

Diffstat:
Mbinary-search-tree/BinarySearchTree.pm | 22++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/binary-search-tree/BinarySearchTree.pm b/binary-search-tree/BinarySearchTree.pm @@ -48,13 +48,19 @@ sub tree { sub in_order { my($tree) = @_; - my @order; - return unless $tree; - in_order($tree->{left}); - print $tree->{data}, " "; - push @order => $tree->{data}; - in_order($tree->{right}); - return \@order; +# my @order; + return () unless $tree; +# in_order($tree->{left}); +# #print $tree->{data}, " "; +# push @order => $tree->{data}; +# in_order($tree->{right}); +# say "my order is @order"; +# return \@order; + return ( + in_order($tree->{left}), + $tree->{data}, + in_order($tree->{right}) + ); } # You are expected to create a tree and then do an in-order walk. @@ -62,7 +68,7 @@ sub in_order { sub treeSort { my ($data) = @_; my $tree = tree ( $data ); - return in_order( $tree ); + return [in_order( $tree )]; } 1;