on Fri, 30 Aug 2002 08:22:56 GMT, [EMAIL PROTECTED] 
(David Samuelsson) wrote:

> i get an array conataining a lot off numbers like this:
> 
> 567

[snipped]

> 520
> 
> how do i find the lowest or the higest number in this series?

There is no need to sort the full array (as others suggested) to just 
find the lowest and highest number when an O(n) operation will 
suffice:

    my ($min, $max);
    $min = $max = $array[0];
    for (1..@array-1) {
        $min = $array[$_] if $array[$_] < $min;
        $max = $array[$_] if $array[$_] > $max;
    }
    print "min = $min, max = $max\n";

-- 
felix
  

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to