in reply to sort an array with +ve & -ve numbers in it
You don't need to sort the array to get the minimum and maximum values, a simple loop will do:
$ perl -le' my @array = ( 99, 67, 0, -100, -38, 98 ); my ( $min, $max ) = @array; for my $element ( @array ) { $min = $element if $min > $element; $max = $element if $max < $element; } print "Min = $min and Max = $max"; ' Min = -100 and Max = 99
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sort an array with +ve & -ve numbers in it
by eric256 (Parson) on Apr 03, 2009 at 13:16 UTC | |
by lostjimmy (Chaplain) on Apr 03, 2009 at 15:26 UTC | |
by eric256 (Parson) on Apr 03, 2009 at 15:58 UTC | |
by plobsing (Friar) on Apr 05, 2009 at 14:28 UTC | |
by philipbailey (Curate) on Apr 03, 2009 at 14:38 UTC | |
by grinder (Bishop) on Apr 03, 2009 at 21:52 UTC |