Skip to content

Instantly share code, notes, and snippets.

@gideondsouza
Created October 20, 2013 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gideondsouza/7068738 to your computer and use it in GitHub Desktop.
Save gideondsouza/7068738 to your computer and use it in GitHub Desktop.
elegant perl quick sort
use strict;
use warnings;
use v5.10;
sub sort_
{
my @xs = @_;
if(scalar(@xs) == 0) {return ();}
my @lesser = sort_(grep { $_ < $xs[0] } @xs);
my @greater = sort_(grep { $_ > $xs[0] } @xs);
return (@lesser, $xs[0], @greater);
}
my @items = (101, 1,90,10,4,2,100);
say join ",", sort_ @items;
@Cassandra-d
Copy link

It doesn't work with equal values in the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment