Sorting algorithms/Quicksort: Difference between revisions

Content added Content deleted
(Add Miranda)
Line 6,436: Line 6,436:
{{out}}
{{out}}
<pre>[1, 2, 3, 4, 5]</pre>
<pre>[1, 2, 3, 4, 5]</pre>

=={{header|Miranda}}==
<syntaxhighlight lang="miranda">main :: [sys_message]
main = [Stdout ("Before: " ++ show testlist ++ "\n"),
Stdout ("After: " ++ show (quicksort testlist) ++ "\n")]
where testlist = [4,65,2,-31,0,99,2,83,782,1]

quicksort [] = []
quicksort [x] = [x]
quicksort xs = (quicksort less) ++ equal ++ (quicksort more)
where pivot = hd xs
less = [x | x<-xs; x<pivot]
equal = [x | x<-xs; x=pivot]
more = [x | x<-xs; x>pivot]</syntaxhighlight>
{{out}}
<pre>Before: [4,65,2,-31,0,99,2,83,782,1]
After: [-31,0,1,2,2,4,65,83,99,782]</pre>


=={{header|Modula-2}}==
=={{header|Modula-2}}==