Skip to content

Instantly share code, notes, and snippets.

@mirasrael
Created November 18, 2018 06:36
Show Gist options
  • Save mirasrael/c47c762f67f0be37518042995bd3cd1a to your computer and use it in GitHub Desktop.
Save mirasrael/c47c762f67f0be37518042995bd3cd1a to your computer and use it in GitHub Desktop.
Array utility functions for Kotlin lessons
import java.util.*
/**
* Date: 11/18/2018
* Time: 09:26
*/
fun printArray(a: LongArray) {
var i = 0
while (i < a.size) {
print(a[i++])
print(' ')
}
println()
}
fun randomArray(n: Int): LongArray {
val r = Random()
val a = LongArray(n)
var i = 0
while (i < n) {
a[i++] = r.nextLong()
}
return a
}
fun swap(input: LongArray, index1: Int, index2: Int) {
val tmp = input[index1]
input[index1] = input[index2]
input[index2] = tmp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment