Created
November 18, 2018 06:36
-
-
Save mirasrael/c47c762f67f0be37518042995bd3cd1a to your computer and use it in GitHub Desktop.
Array utility functions for Kotlin lessons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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