in reply to Re: getting the highest value in a simpler way
in thread getting the highest value in a simpler way

Replicant4 What I am actually asking is that I don't really need to store all the values I just need the maximum. So is there a way that instead of using an array, I can just store mutual and every time that my program goes through the loop, if mutual is higher then it will be replaced. My actual problem is that for every round ~1500x1500 calculations are being processed and this takes up a very large amount of time. Thanks
  • Comment on Re^2: getting the highest value in a simpler way

Replies are listed 'Best First'.
Re^3: getting the highest value in a simpler way
by borisz (Canon) on Nov 10, 2004 at 12:48 UTC
    Here is another way:
    package XX::Maximum; sub new { my ( $class, $value ) = @_; bless \$value, $class } sub set { ${$_[0]} = $_[1] } sub get { ${$_[0]} } sub insert { return ${$_[0]} unless defined $_[1]; return ${$_[0]} = ( !defined(${$_[0]} ) ? $_[1] : ( ${$_[0]} > $_[1] + ? ${$_[0]} : $_[1] )); } package main; my $t = XX::Maximum->new; $t->insert(1); $t->insert(0); $t->insert(undef); print $$t, "\n"; $t->insert(-10); print $$t, "\n"; $t->insert(10); print $$t, "\n"; print $t->get, "\n"; $t->set(undef);
    Boris