0 Replies - 1350 Views - Last Post: 18 January 2010 - 04:56 PM

#1 chorny_cpan   User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 52
  • Joined: 13-May 09

min max index

Posted 18 January 2010 - 04:56 PM

Description: Searching indexes of maximum and minimum values of an array. Complexity O(n).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: $maxn";
print "index min: $minn";

#(c) Alexandr Ciornii



Is This A Good Question/Topic? 0
  • +

Page 1 of 1