Skip to content

Instantly share code, notes, and snippets.

@opamp
Created June 17, 2013 05:17
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 opamp/5794767 to your computer and use it in GitHub Desktop.
Save opamp/5794767 to your computer and use it in GitHub Desktop.
practice in scala. QuickSort
val ar = Array(79,56,89,100,1,2,6,5,90,21,26,75,35,67,66,65,81,10,0)//適当な配列 (0 <= x <= 100)
def qs(a:Array[Int]):Array[Int] = {
if(a.length == 1) return a
val pivot = if(a(0) > a(1)) a(0) else a(1)
val a0 = qs(a.filter( _ < pivot))
val a1 = qs(a.filter( _ >= pivot))
Array.concat(a0,a1)
}
qs(ar).foreach{
println
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment