Created
May 29, 2018 08:45
-
-
Save S2/2e36a8ce65447a9e5067d16a8a71b84d to your computer and use it in GitHub Desktop.
BubbleSort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.16.2; | |
use strict; | |
use warnings; | |
use utf8; | |
use String::Random qw/random_regex/; | |
use Test::More; | |
for(1..20){ | |
my $i = [map{0 + random_regex '\d{3}'}1..150]; | |
my $s = 1; | |
while($s){ | |
$s = 0; | |
for(0..@$i - 2){ | |
if($i->[$_] > $i->[$_ + 1]){ | |
@$i[$_ , $_ + 1] = @$i[$_ + 1 , $_]; | |
$s = 1 | |
} | |
} | |
} | |
is_deeply [sort {$a <=> $b}@$i] , $i; | |
} | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment