public
Last active

  • Download Gist
quicksort.scala
Scala
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/sh
exec scala "$0" "$@"
!#
 
def quicksort(l: List[Int]): List[Int] = l match {
case Nil => Nil
case p :: xs =>
val (l1, l2) = xs.partition(_ < p)
quicksort(l1) ::: p :: quicksort(l2)
}
 
println(quicksort(List(10,5,999,42,3,1)).mkString(" "))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.