I see what you mean

I assume the following would be a better way of going at it

$max = $min = $data[0];
foreach $val (@data) {
    $min = $val<$min ? $val:$min;
    $max = $val>$max ? $val:$max;
}

Robert

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of
Sudarsan Raghavan
Sent: 27 March 2002 14:26
Cc: [EMAIL PROTECTED]
Subject: Re: Maximum ,Minumum


Robert Graham wrote:

> Hi Ozgur
>
> You can use the following:
>
> @data = (10,45,2,439);
> ($min,$max) = (sort {$a <=> $b} @data)[0,$#data];

    IMHO sorting a list to find the max and min element is not a good idea.
The sort is of O(nlgn) and the usual
    run through the list to find the max element is O(n). This is not of
significance when n is small, at the same
    time this is not a method that should be followed for this task.

>
>
> Regards
> Robert
>
> -----Original Message-----
> From: OZGUR GENC [mailto:[EMAIL PROTECTED]]
> Sent: 27 March 2002 13:06
> To: [EMAIL PROTECTED]
> Subject: Maximum ,Minumum
>
> Hi All,
> Does anyone help me about how I can find the maximum and minumum element
> of an array?
> Ozgur
>
>
***************************************************************************
>
> This e-mail and any files transmitted with it are confidential and
intended
> solely for the use of the individual or entity to whom they are addressed.
> If you are not the intended recipient you are hereby notified that any
> dissemination, forwarding, copying or use of any of the information is
> prohibited.
>
> The opinions expressed in this message belong to sender alone. There is no
> implied endorsement by TURKCELL.
>
> This e-mail has been scanned for all known computer viruses.
>
>
***************************************************************************
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


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


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

Reply via email to