Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Algorithms/Find maximum/perl method2

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

perl source code sub findmax_apple(){ return 0 if $#_ == -1; return $_[0] if $#_ == 0; if ( $#_ == 1 ) { return $_[0] if $_[0] > $_[1]; return $_[1]; } my @aryA; my @aryB; foreach my $i ( 1 .. ($#_+1)/2 ){ push ( @aryA, $_[ $i - 1 ] ); } foreach my $i ( $#aryA + 1 .. $#_ ){ push ( @aryB, $_[$i] ); } my $intM = &findmax_apple(@aryA); my $intN = &findmax_apple(@aryB); return $intM if $intM > $intN; return $intN; } An example of using the subroutine: print &findmax_apple(qw/ 1 100 182 32 476 /); The output should be: 476.