Created
April 3, 2015 12:45
-
-
Save akhileshs/60331456cdae16464a30 to your computer and use it in GitHub Desktop.
simple quick sort
This file contains 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
scala> def qsort(xs: List[Int]): List[Int] = { | |
| if (xs.length <= 1) xs | |
| else { | |
| val pivot = xs(xs.length / 2) | |
| qsort(xs filter (_ < pivot)) ++ List(pivot) ++ qsort(xs filter (_ > pivot)) | |
| } | |
| } | |
qsort: (xs: List[Int])List[Int] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment