all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,16 @@
|
|||
def bubbleSort[T](arr: Array[T])(implicit o: Ordering[T]) {
|
||||
import o._
|
||||
val consecutiveIndices = (arr.indices, arr.indices drop 1).zipped
|
||||
var hasChanged = true
|
||||
do {
|
||||
hasChanged = false
|
||||
consecutiveIndices foreach { (i1, i2) =>
|
||||
if (arr(i1) > arr(i2)) {
|
||||
hasChanged = true
|
||||
val tmp = arr(i1)
|
||||
arr(i1) = arr(i2)
|
||||
arr(i2) = tmp
|
||||
}
|
||||
}
|
||||
} while(hasChanged)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue