June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,20 @@
object StoogeSort extends App {
def stoogeSort(a: Array[Int], i: Int, j: Int) {
if (a(j) < a(i)) {
val temp = a(j)
a(j) = a(i)
a(i) = temp
}
if (j - i > 1) {
val t = (j - i + 1) / 3
stoogeSort(a, i, j - t)
stoogeSort(a, i + t, j)
stoogeSort(a, i, j - t)
}
}
val a = Array(100, 2, 56, 200, -52, 3, 99, 33, 177, -199)
println(s"Original : ${a.mkString(", ")}")
stoogeSort(a, 0, a.length - 1)
println(s"Sorted : ${a.mkString(", ")}")
}