Selection Sort in Perl

Perl script to Implement Selection Sort. This Algorithm is very simple. Find the smallest element in the array and swap it. That's all you will get a sorted array in the end.

Source code :


@array = (1,45,10,35,100,13,147,500,80);
$size = @array;
$min = 0;

for ($i = 0; $i < $size ; $i=$i+1){
    
    for($j = $i+1  ; $j < $size ; $j=$j+1){
        
        if($array[$j] < $array[$i]){
            
            $min = $array[$j];
            $array[$j] = $array[$i];
            $array[$i] = $min;
            
        }
    }
    
    break;
    
}

foreach $number (@array){
    
print $number. "
";
    
}




Output :

1
10
13
35
45
80
100
147
500

Output :


                

Comments :