line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::MinMax; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23870
|
use 5.6.1; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
62
|
|
4
|
1
|
|
|
1
|
|
10
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
55
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
691
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
12
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
13
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# This allows declaration use Algorithm::MinMax ':all'; |
16
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
17
|
|
|
|
|
|
|
# will save memory. |
18
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
) ] ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT = qw( |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Preloaded methods go here. |
31
|
|
|
|
|
|
|
sub minmax { |
32
|
0
|
|
|
0
|
0
|
|
my @array = @{ $_[ 1 ] }; |
|
0
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my @result; |
34
|
0
|
0
|
|
|
|
|
if( scalar( @array ) == 0 ) { |
35
|
0
|
|
|
|
|
|
return @result; |
36
|
|
|
|
|
|
|
} |
37
|
0
|
0
|
|
|
|
|
if( scalar( @array ) == 1 ) { |
38
|
0
|
|
|
|
|
|
$result[ 0 ] = $array[ 0 ]; |
39
|
0
|
|
|
|
|
|
$result[ 1 ] = $array[ 0 ]; |
40
|
0
|
|
|
|
|
|
return @result; |
41
|
|
|
|
|
|
|
} |
42
|
0
|
|
|
|
|
|
my @min_cand; |
43
|
|
|
|
|
|
|
my @max_cand; |
44
|
0
|
|
|
|
|
|
my $r = scalar( @array ) - 2; |
45
|
0
|
|
|
|
|
|
my $k = 0; |
46
|
0
|
|
|
|
|
|
for( my $i = 0; $i <= $r ; $i = $i + 2 ) { |
47
|
0
|
0
|
|
|
|
|
if( $array[ $i ] < $array[ $i + 1 ] ) { |
48
|
0
|
|
|
|
|
|
$min_cand[ $k ] = $array[ $i ]; |
49
|
0
|
|
|
|
|
|
$max_cand[ $k ] = $array[ $i + 1 ]; |
50
|
|
|
|
|
|
|
} else { |
51
|
0
|
|
|
|
|
|
$min_cand[ $k ] = $array[ $i + 1 ]; |
52
|
0
|
|
|
|
|
|
$max_cand[ $k ] = $array[ $i ]; |
53
|
|
|
|
|
|
|
} |
54
|
0
|
|
|
|
|
|
++$k; |
55
|
|
|
|
|
|
|
} |
56
|
0
|
0
|
|
|
|
|
if( scalar( @array ) % 2 != 0 ) { |
57
|
0
|
0
|
|
|
|
|
if( $min_cand[ 0 ] < $array[ $r + 1 ] ) { |
58
|
0
|
|
|
|
|
|
$max_cand[ $k ] = $array[ $r + 1 ]; |
59
|
|
|
|
|
|
|
} else { |
60
|
0
|
|
|
|
|
|
$min_cand[ $k ] = $array[ $r + 1 ]; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
my $m = $min_cand[ 0 ]; |
64
|
0
|
|
|
|
|
|
for( my $i = 1; $i < scalar( @min_cand ); ++$i ) { |
65
|
0
|
0
|
|
|
|
|
if( $min_cand[ $i ] < $m ) { |
66
|
0
|
|
|
|
|
|
$m = $min_cand[ $i ]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
$result[ 0 ] = $m; |
70
|
0
|
|
|
|
|
|
$m = $max_cand[ 0 ]; |
71
|
0
|
|
|
|
|
|
for( my $i = 1; $i < scalar( @max_cand ); ++$i ) { |
72
|
0
|
0
|
|
|
|
|
if( $max_cand[ $i ] > $m ) { |
73
|
0
|
|
|
|
|
|
$m = $max_cand[ $i ]; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
0
|
|
|
|
|
|
$result[ 1 ] = $m; |
77
|
0
|
|
|
|
|
|
@result; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
__END__ |