Created
May 14, 2015 12:31
-
-
Save Ajwah/d834a1d33fd6cb8f5d0b to your computer and use it in GitHub Desktop.
efficient quicksort implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(*Source: http://www.webber-labs.com/mpl/source%20code/Chapter%20Twelve/quicksort.sml.txt *) | |
fun quicksort nil = nil | |
| quicksort (pivot :: rest) = | |
let | |
fun split(nil) = (nil,nil) | |
| split(x :: xs) = | |
let | |
val (below, above) = split(xs) | |
in | |
if x < pivot then (x :: below, above) | |
else (below, x :: above) | |
end; | |
val (below, above) = split(rest) | |
in | |
quicksort below @ [pivot] @ quicksort above | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment