From f9daa08e2104599a6fedc78b2b703e8ca81ca66d Mon Sep 17 00:00:00 2001 From: Lakpa Tashi Bhutia Date: Mon, 10 May 2021 13:40:39 +0530 Subject: Rename ch-1.pl to ch-2.pl --- challenge-018/lakpatashi/perl/ch-1.pl | 45 ----------------------------------- challenge-018/lakpatashi/perl/ch-2.pl | 45 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 45 deletions(-) delete mode 100755 challenge-018/lakpatashi/perl/ch-1.pl create mode 100755 challenge-018/lakpatashi/perl/ch-2.pl diff --git a/challenge-018/lakpatashi/perl/ch-1.pl b/challenge-018/lakpatashi/perl/ch-1.pl deleted file mode 100755 index de0fa545e0..0000000000 --- a/challenge-018/lakpatashi/perl/ch-1.pl +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/perl - -use warnings; -use strict; -use Data::Dumper; -use List::Util qw(sum min); -use feature qw(switch); - -#part 2 -my %priorityQ = (1 => ['apple','ball']); -insert_with_priority(\%priorityQ,'cat',2); -print pull_highest_priority_element(\%priorityQ),"\n"; -print pull_highest_priority_element(\%priorityQ),"\n"; -if( is_empty(\%priorityQ) ){ - print "empty\n"; -}else{ - print "not empty\n"; -} - -sub insert_with_priority{ - #(pQ,ele,priority) - my ($pQ,$val,$key) = @_; - if( $pQ->{$key} ){ #if key exist - push( $pQ->{$key},$val ); - }else{ - $pQ->{$key} = [$val] ; #key doesn't exist - } -} -sub pull_highest_priority_element{ - #(pQ) - my ($pQ) = @_; - my $key = min keys $pQ; - my $val = shift( $pQ->{$key} ); - delete $pQ->{$key} unless @{$pQ->{$key}}; - return $val; -} - -sub is_empty{ - #(pQ) - my ($pQ) = @_; - return not scalar %{$pQ}; -} - -print '='x10," P Queue ",'='x10,"\n"; -print Dumper \%priorityQ; diff --git a/challenge-018/lakpatashi/perl/ch-2.pl b/challenge-018/lakpatashi/perl/ch-2.pl new file mode 100755 index 0000000000..de0fa545e0 --- /dev/null +++ b/challenge-018/lakpatashi/perl/ch-2.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +use warnings; +use strict; +use Data::Dumper; +use List::Util qw(sum min); +use feature qw(switch); + +#part 2 +my %priorityQ = (1 => ['apple','ball']); +insert_with_priority(\%priorityQ,'cat',2); +print pull_highest_priority_element(\%priorityQ),"\n"; +print pull_highest_priority_element(\%priorityQ),"\n"; +if( is_empty(\%priorityQ) ){ + print "empty\n"; +}else{ + print "not empty\n"; +} + +sub insert_with_priority{ + #(pQ,ele,priority) + my ($pQ,$val,$key) = @_; + if( $pQ->{$key} ){ #if key exist + push( $pQ->{$key},$val ); + }else{ + $pQ->{$key} = [$val] ; #key doesn't exist + } +} +sub pull_highest_priority_element{ + #(pQ) + my ($pQ) = @_; + my $key = min keys $pQ; + my $val = shift( $pQ->{$key} ); + delete $pQ->{$key} unless @{$pQ->{$key}}; + return $val; +} + +sub is_empty{ + #(pQ) + my ($pQ) = @_; + return not scalar %{$pQ}; +} + +print '='x10," P Queue ",'='x10,"\n"; +print Dumper \%priorityQ; -- cgit