Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,15 @@
|
|||
import scala.compat.Platform
|
||||
|
||||
object Sort_an_integer_array extends App {
|
||||
val array = Array((for (i <- 0 to 10) yield scala.util.Random.nextInt()):
|
||||
_* /*Sequence is passed as multiple parameters to Array(xs : T*)*/)
|
||||
|
||||
/** Function test the array if it is in order */
|
||||
def isSorted[T](arr: Array[T]) = array.sliding(2).forall(pair => pair(0) <= pair(1))
|
||||
|
||||
assert(!isSorted(array), "Not random")
|
||||
scala.util.Sorting.quickSort(array)
|
||||
assert(isSorted(array), "Not sorted")
|
||||
|
||||
println(s"Array in sorted order.\nSuccessfully completed without errors. [total ${Platform.currentTime - executionStart} ms]")
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
println(List(5,2,78,2,578,-42).sorted)
|
||||
//--> List(-42, 2, 2, 5, 78, 578)
|
||||
Loading…
Add table
Add a link
Reference in a new issue