Skip to content

Instantly share code, notes, and snippets.

@DPS0340
Created August 1, 2019 03:42
Show Gist options
  • Select an option

  • Save DPS0340/298624b3d18a5ba9d88459fd623ffe2d to your computer and use it in GitHub Desktop.

Select an option

Save DPS0340/298624b3d18a5ba9d88459fd623ffe2d to your computer and use it in GitHub Desktop.
quick sort scala
def qsort(lst: List[Int]): List[Int] = lst match {
case Nil => Nil
case x :: xs => qsort(xs.filter(_ <= x)) ::: List(x) ::: qsort(xs.filter(_ > x))
}
println(qsort(List(15, 3, 6, 7, 9, 1))) // List(1, 3, 6, 7, 9, 15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment