List Info

Thread: Max in an array




Max in an array
country flaguser name
United States
2007-08-30 07:34:28

Hi,

Would you please let me know the efficient way (different ways) to get the
max or nth largest element in an array

--
-SrINIvAS ReDdY....

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: Max in an array
country flaguser name
United States
2007-08-30 07:42:50

--- In perl-beginner%40yahoogroups.com">perl-beginneryahoogroups.com, "srinivas reddy";
<reddysrinivas.k...> wrote:
&gt;
> Hi,
>
> Would you please let me know the efficient way (different ways) to
get the
> max or nth largest element in an array
&gt;
> --
> -SrINIvAS ReDdY....
>
>
> [Non-text portions of this message have been removed]
>

Hi,

Well to be honest this is an algorithm question. But one of them is
using built in functions or a loop and a temp value or binary search.
But note that perl does have his own order for arrays so it's good
practice to order the array first. Although this only applies to
hashes... Well never mind

Gergely.

__._,_.___
.

__,_._,___
Re: Max in an array
country flaguser name
United States
2007-08-30 09:43:22

>>&gt;>> "srinivas" == srinivas reddy < reddysrinivas.k%40gmail.com">reddysrinivas.kgmail.com> writes:

srinivas> Would you please let me know the efficient way (different ways) to get the
srinivas> max or nth largest element in an array

use List::Util;
my $max = max(some_array);

That's the most efficient, because it's implemented in C.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<; merlyn%40stonehenge.com">merlynstonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )