Created
December 2, 2017 18:46
-
-
Save haodemon/70dfe4b8d232cc4fc5b1622a2b611cd5 to your computer and use it in GitHub Desktop.
Eloquent quicksort implementation (Perl)
This file contains hidden or 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 Test::Deep; | |
sub quicksort { | |
return unless @_; | |
my $pivot = shift; | |
return ( | |
quicksort(grep { $_ < $pivot } @_), | |
$pivot, | |
quicksort(grep { $_ >= $pivot } @_) | |
); | |
} | |
my @unsorted = (12, 4, 5, -12, 66, 0, 1111, 2); | |
my @sorted = (-12, 0, 2, 4, 5, 12, 66, 1111); | |
cmp_deeply([@sorted], [quicksort(@unsorted)]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment