Skip to content

Instantly share code, notes, and snippets.

@nlw0
Created May 5, 2017 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nlw0/97023bf1411632dab43b3a9fd2d28b6d to your computer and use it in GitHub Desktop.
Save nlw0/97023bf1411632dab43b3a9fd2d28b6d to your computer and use it in GitHub Desktop.
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