use strict;
use warnings;
my $trials = 10;
my %h = map { int rand $trials => 1 } 1..$trials;
my @target = keys %h;
print join(" ", @target);
print "\n";
@target = bubble_sort(@target);
sub bubble_sort {
my @ary = @_;
for my $i (reverse 0..($#ary-1)) {
for my $j (0..$i) {
next if $ary[$j] <= $ary[$j+1];
($ary[$j], $ary[$j+1] ) = ($ary[$j+1], $ary[$j] );
print join(" ", @ary);
print "\n";
}
}
@ary;
}
8 1 4 0 3 9 2
1 8 4 0 3 9 2
1 4 8 0 3 9 2
1 4 0 8 3 9 2
1 4 0 3 8 9 2
1 4 0 3 8 2 9
1 0 4 3 8 2 9
1 0 3 4 8 2 9
1 0 3 4 2 8 9
0 1 3 4 2 8 9
0 1 3 2 4 8 9
0 1 2 3 4 8 9