Skip to content

Instantly share code, notes, and snippets.

@notyy
Created October 25, 2011 14:34
Show Gist options
  • Save notyy/1312942 to your computer and use it in GitHub Desktop.
Save notyy/1312942 to your computer and use it in GitHub Desktop.
how to implement this in scala?
quicksort' :: (Ord a) => [a] -> [a]
quicksort' [] = []
quicksort' (x:xs) = smaller ++ [x] ++ bigger
where smaller = quicksort' $ filter (<=x) xs
bigger = quicksort' $ filter (>x) xs
@notyy
Copy link
Author

notyy commented Oct 25, 2011

solved, thanks老猪
def quicksort[T : Ordering](l: List[T]) : List[T] = l match {
case Nil => Nil
case x :: xs =>
val ord = Ordering[T]
import ord._

val smaller = quicksort(xs.filter(_<=x))
val bigger = quicksort(xs.filter(_>x))
smaller ++ List(x) ++ bigger

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment