Created
October 20, 2013 12:15
-
-
Save gideondsouza/7068738 to your computer and use it in GitHub Desktop.
elegant perl quick 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
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; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It doesn't work with equal values in the list.