katien
02/25/2018, 11:57 PMclass ResizableArray<K> {
var array: Array<Any?> = arrayOfNulls(256)
var size = 0
fun add(value: K) {
array[size] = value
size++
if (size == array.size)
array = Array(array.size * 2, { if (it < size) array[it] else null })
}
operator fun get(index: Int): K {
if (index < size)
return array[index] as K
else
throw IndexOutOfBoundsException("The array is only $size long you can't access index $index")
}
operator fun set(index: Int, value: K) {
if (index < size)
array[index] = value
else
throw IndexOutOfBoundsException("The array is only $size long you can't access index $index")
}
}