exercism-perl5

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

commit 25b47bc24f0bb587ebb0a986d2a1f77dc9f058ee
parent 2f5a8088073198abd9c2ee9f76e3d80dc7932122
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Wed,  5 Jan 2022 02:32:39 +0000

start work on in order sort

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

diff --git a/binary-search-tree/BinarySearchTree.pm b/binary-search-tree/BinarySearchTree.pm @@ -41,16 +41,28 @@ sub insert { sub tree { my ($data) = @_; - my $root; - insert ( $root, $_ ) foreach (@{$data}); - return $root; + my $tree; + insert ( $tree, $_ ) foreach ( @{ $data } ); + return $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; } # You are expected to create a tree and then do an in-order walk. # Using the sort() function is cheating! sub treeSort { my ($data) = @_; - return undef; + my $tree = tree ( $data ); + return in_order( $tree ); } 1;