Created
August 5, 2017 10:21
-
-
Save khajavi/b8381efd51aa2b72733727a5c28d1977 to your computer and use it in GitHub Desktop.
Recursive QuickSort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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