Created
July 26, 2013 01:58
-
-
Save Puriney/6085457 to your computer and use it in GitHub Desktop.
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
#http://rosettacode.org/wiki/Sorting_algorithms/Quicksort#Perl | |
sub quick_sort { | |
my @a = @_; | |
return @a if @a < 2; | |
my $p = pop @a; | |
quick_sort(grep $_ < $p, @a), $p, quick_sort(grep $_ >= $p, @a); | |
} | |
my @array = (1,4,2,3,6,5,8,7); | |
@array = quick_sort @array; | |
print "@array\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment