Skip to content

Instantly share code, notes, and snippets.

@jedws
Created August 6, 2011 00:24
Show Gist options
  • Save jedws/1128825 to your computer and use it in GitHub Desktop.
Save jedws/1128825 to your computer and use it in GitHub Desktop.
object Sort {
def qsort[A, CC[A] <: TraversableLike[A, CC[A]]](c: CC[A])(implicit ord : Ordering[A], bf: CanBuildFrom[CC[A], A, CC[A]]) : CC[A] = {
if (c.isEmpty || c.tail.isEmpty) c
else {
val pivot = c.head
val (low: CC[A], high: CC[A]) = c.tail.partition{ ord.lt(_, pivot) }
qsort(low) ++ bf().+=(pivot).result ++ qsort(high)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment