Created
February 4, 2010 21:18
-
-
Save dannylagrouw/295118 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def split[A <% Ordered[A]](list: List[A], p: A): (List[A], List[A]) = list match { | |
case e :: rest => | |
val (left, right) = split(rest, p) | |
if (e < p) | |
(e :: left, right) | |
else | |
(left, e :: right) | |
case _ => (Nil, Nil) | |
} | |
def qsort[A <% Ordered[A]](list: List[A]): List[A] = list match { | |
case p :: rest => | |
val (left, right) = split(rest, p) | |
qsort(left) ++ (p :: qsort(right)) | |
case _ => Nil | |
} | |
println(qsort(List(1241, 1, 234, 503, 122, 99, 10, 1992, 1200))) | |
println(qsort("quicksort".toList)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment