Skip to content

Instantly share code, notes, and snippets.

@haodemon
Created December 2, 2017 18:46
Show Gist options
  • Save haodemon/70dfe4b8d232cc4fc5b1622a2b611cd5 to your computer and use it in GitHub Desktop.
Save haodemon/70dfe4b8d232cc4fc5b1622a2b611cd5 to your computer and use it in GitHub Desktop.
Eloquent quicksort implementation (Perl)
#!/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