exercism-perl5

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

commit 4bcfc8a56e1b423dc44fec1f03747e45775b7304
parent a88c3a1888a9e6f656dbcf5fb2450fa36b08e520
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Wed,  5 Jan 2022 20:17:41 +0000

cleanup code

Diffstat:
Mbinary-search-tree/BinarySearchTree.pm | 17++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/binary-search-tree/BinarySearchTree.pm b/binary-search-tree/BinarySearchTree.pm @@ -10,9 +10,6 @@ our @EXPORT_OK = qw<tree treeSort>; # https://www.oreilly.com/library/view/perl-cookbook/1565922433/ # -use v5.22; -use Data::Dumper; - sub create_new_node { my $value = shift; # create anonymous array to represent the new node @@ -46,19 +43,14 @@ sub tree { return $tree; } +# recurse on left subtree, obtain root, recurse on right tree +# until we get to empty node 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}); -# say "my order is @order"; -# return \@order; return ( in_order($tree->{left}), - $tree->{data}, + $tree->{data}, in_order($tree->{right}) ); } @@ -67,8 +59,7 @@ sub in_order { # Using the sort() function is cheating! sub treeSort { my ($data) = @_; - my $tree = tree ( $data ); - return [in_order( $tree )]; + return [in_order( tree ( $data ) )]; } 1;