Sorting algorithms/Quicksort: Difference between revisions

Content added Content deleted
(→‎{{header|Prolog}}: Added PureBasic)
Line 992:
=={{header|Perl}}==
<lang perl>sub quick_sort {
$my @arr = shift@_;
localmy $@less = [];
localmy $@pivot_list = [];
localmy $@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}];
}
}
 
print join(' ', @{quick_sort([4, 65, 2, -31, 0, 99, 83, 782, 1])}), "\n";</lang>
 
Output: