Created
May 5, 2017 19:32
-
-
Save nlw0/97023bf1411632dab43b3a9fd2d28b6d to your computer and use it in GitHub Desktop.
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
object Quicksort extends App { | |
val inputStream = io.Source.fromInputStream(System.in) | |
val data = inputStream.getLines().toList map (_.toInt) | |
quicksort(data) foreach { println(_) } | |
def quicksort(x: List[Int]): List[Int] = if (x.isEmpty) List() else { | |
val pivot = x.head | |
val (a, b) = x.tail.partition(_ <= pivot) | |
val coisa = quicksort(a) ::: pivot :: quicksort(b) | |
println(coisa) | |
coisa | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment