Skip to content

Instantly share code, notes, and snippets.

@kazua
Created October 12, 2012 16:35
Show Gist options
  • Save kazua/3880135 to your computer and use it in GitHub Desktop.
Save kazua/3880135 to your computer and use it in GitHub Desktop.
scalaでクイックソート
object qksort {
def qksort(sl: List[Int]): List[Int] = {
sl match {
case List() => sl
case slh::sll => qksort(sll.filter(slh > _)) ::: List(slh) ::: qksort(sll.filter(slh < _))
}
}
def main(args: Array[String]) {
val ls = List(5, 27, 15, 31, 13, 23, 49, 16, 53, 39, 24, 11, 21, 63, 87)
qksort(ls).foreach{println}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment