Skip to content

Instantly share code, notes, and snippets.

@ppurang
Created July 21, 2011 16:45
Show Gist options
  • Save ppurang/1097596 to your computer and use it in GitHub Desktop.
Save ppurang/1097596 to your computer and use it in GitHub Desktop.
quicksort

quicksort

scala

def qsort[A <% Ordered[A]](v: Seq[A]): Seq[A] = v.headOption match {
  case Some(x) => (qsort(v.tail.filter(_ < x)) :+ x) ++ qsort(v.tail.filter(_ >= x))
  case _ => Seq()
}

haskell

qsort :: Ord a => [a] -> [a]
qsort [] = []
qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment