Created
March 16, 2019 16:33
Star
You must be signed in to star a gist
bubble_sort
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 strict; | |
use warnings; | |
use feature 'say'; | |
use DDP { deparse => 1 }; | |
my @seeds; | |
for (1..100){ | |
push(@seeds, int(rand(100))); | |
} | |
p @seeds; | |
my @endpoints = reverse(1..(scalar @seeds - 2)); | |
for my $i (@endpoints){ | |
for my $j (0..$i){ | |
my $f = $seeds[$j]; | |
my $s = $seeds[$j + 1]; | |
if ($f > $s){ | |
$seeds[$j] = $s; | |
$seeds[$j + 1] = $f; | |
} | |
} | |
} | |
p @seeds; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment