Created
August 1, 2019 03:42
-
-
Save DPS0340/298624b3d18a5ba9d88459fd623ffe2d to your computer and use it in GitHub Desktop.
quick sort scala
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
| 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