Sorting algorithms/Quicksort: Difference between revisions

(→‎{{header|OCaml}}: Add imperative, in place implementation)
Line 5,155:
</lang>
<pre>The output is: 3 8 11 19 21 36 60 63 80 87 100</pre>
 
 
===Yet another solution===
<lang powershell>
function quicksort($in) {
$n = $in.count
switch ($n) {
0 {}
1 { $in[0] }
2 { if ($in[0] -lt $in[1]) {$in[0], $in[1]} else {$in[1], $in[0]} }
default {
$pivot = $in | get-random
$lt = $in | ? {$_ -lt $pivot}
$eq = $in | ? {$_ -eq $pivot}
$gt = $in | ? {$_ -gt $pivot}
@(quicksort $lt) + @($eq) + @(quicksort $gt)
}
}
}
</lang>
 
=={{header|Prolog}}==
Anonymous user