|
|
|
Detect indexes of max and min values of an array
1
Detect indexes of max and min values of an array in Perl
#Detect indexes of max and min values of an array in Perl
use strict;
use warnings;
my ($min,$max);
$min=$max=0;
my @list=(1,7,2,-2,7,0,-1);
foreach my $i (1..$#list) {
$min=$i if $list[$i]<$list[$min];
$max=$i if $list[$i]>$list[$max];
}
print "index max: $max\n";
print "index min: $min\n";
#(c) Alexandr Ciornii




There are currently no comments for this snippet.