Sorting algorithms/Quicksort: Difference between revisions

Content added Content deleted
m (Added to recursion category)
(Added Perl version.)
Line 267: Line 267:
a = #(4, 89, -3, 42, 5, 0, 2, 889)
a = #(4, 89, -3, 42, 5, 0, 2, 889)
a = quickSort a
a = quickSort a

=={{header|Perl}}==
sub quick_sort {
$arr = shift;
$less = [];
$pivot_list = [];
$more = [];
if ($#{$arr} <= 0) {
return $arr;
} else {
$pivot = $arr->[0];
foreach my $i (@{$arr}) {
if ($i < $pivot) {
push @{$less}, $i;
} elsif ($i > $pivot) {
push @{$more}, $i;
} else {
push @{$pivot_list}, $i;
}
}
$less = quick_sort($less);
$more = quick_sort($more);
return [@{$less}, @{$pivot_list}, @{$more}];
}
}


=={{header|Python}}==
=={{header|Python}}==