blob: ce87ef0702dd02b9cc0e59f5868a6680561b5218 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
use strict;
use warnings;
my @A = (7, 8, 3, 12, 10);
my @small;
foreach (0..$#A) # Traverse the array
{
my $small;
if($_>0) #check if the index value greater than zero,if no left index value put minimum as zero
{
foreach(0..$_-1) # traverse the left index elements
{
$small = $A[$_] if(!defined $small || $A[$_] < $small); #find minimum of left element
}
$small =0 if($A[$_] < $small); #minimum as zero if no left value smaller
push (@small, $small);
}
else
{
$small = 0; #no left value for index is zero
push (@small, $small);
}
}
print "@small";
|