Skip to content

Instantly share code, notes, and snippets.

@khajavi
Created August 5, 2017 10:21
Show Gist options
  • Save khajavi/b8381efd51aa2b72733727a5c28d1977 to your computer and use it in GitHub Desktop.
Save khajavi/b8381efd51aa2b72733727a5c28d1977 to your computer and use it in GitHub Desktop.
Recursive QuickSort
object QuickSort extends App {
val list = List(3, 5, 7, 1, 4, 9, 44, 2)
println(quickSort(list))
def quickSort(list: List[Int]): List[Int] = {
list match {
case Nil => Nil
case pivot :: tail =>
val (less, greater) = tail.partition(_ < pivot)
quickSort(less) ::: pivot :: quickSort(greater)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment