Sorting algorithms/Quicksort: Difference between revisions

Content added Content deleted
(Updated first D entry)
m (added FunL)
Line 1,578:
 
A discussion about Quicksort pivot options, free source code for an optimized quicksort using insertion sort as a finisher, and an OpenMP multi-threaded quicksort is found at [http://balfortran.org balfortran.org]
 
=={{header|FPr}}==
<lang FPr>qsort==nilp->id;
((qsort°3)++1,qsort°4)
°((not°nilp°2)->*1,(tail°2),(1>1°2)->(((1°2),3),4,nil);3,((1°2),4),nil)
°1,tail,(nil as _1),(nil as _1),nil
</lang>
 
=={{header|FunL}}==
<lang funl>def
qsort( [] ) = []
qsort( p:xs ) = qsort( xs.filter((< p), xs) ) + [p] + qsort( xs.filter((>= p), xs) )</lang>
 
Here is a more efficient version using the <code>partition</code> function.
 
<lang funl>import lists.partitiondef
 
def
qsort( [] ) = []
qsort( x:xs ) =
val (ys, zs) = xs.partition( (< x), xs )
qsort( ys ) + (x : qsort( zs ))
 
println( qsort([4, 2, 1, 3, 0, 2]) )
println( qsort(["BobJuan", "AliceDaniel", "BarryMiguel", "ZoeWilliam", "CharlotteLiam", "FredEthan", "Jacob"]) )</lang>
 
{{out}}
Line 1,608 ⟶ 1,599:
<pre>
[0, 1, 2, 2, 3, 4]
[AliceDaniel, BarryEthan, BobJacob, CharlotteJuan, FredLiam, ZoeMiguel, William]
</pre>