Sorting algorithms/Quicksort: Difference between revisions
Content added Content deleted
PatGarrett (talk | contribs) (→{{header|360 Assembly}}: Replaced my old vervion with a more structured one) |
|||
Line 3,924: | Line 3,924: | ||
}</lang> |
}</lang> |
||
Note that <code>$before</code> and <code>$after</code> are bound to lazy lists, so the partitions can (at least in theory) be sorted in parallel. |
Note that <code>$before</code> and <code>$after</code> are bound to lazy lists, so the partitions can (at least in theory) be sorted in parallel. |
||
=={{header|Phix}}== |
|||
<lang Phix>function quick_sort(sequence x) |
|||
-- |
|||
-- put x into ascending order using recursive quick sort |
|||
-- |
|||
integer n, last, mid |
|||
object xi, midval |
|||
n = length(x) |
|||
if n<2 then |
|||
return x -- already sorted (trivial case) |
|||
end if |
|||
mid = floor((n+1)/2) |
|||
midval = x[mid] |
|||
x[mid] = x[1] |
|||
last = 1 |
|||
for i=2 to n do |
|||
xi = x[i] |
|||
if xi<midval then |
|||
last += 1 |
|||
x[i] = x[last] |
|||
x[last] = xi |
|||
end if |
|||
end for |
|||
return quick_sort(x[2..last]) & {midval} & quick_sort(x[last+1..n]) |
|||
end function |
|||
?quick_sort({5,"oranges","and",3,"apples"})</lang> |
|||
{{out}} |
|||
<pre> |
|||
{3,5,"and","apples","oranges"} |
|||
</pre> |
|||
=={{header|PHP}}== |
=={{header|PHP}}== |