diff --git a/src/main/io/uuddlrlrba/ktalgs/datastructures/PriorityQueue.kt b/src/main/io/uuddlrlrba/ktalgs/datastructures/PriorityQueue.kt index 526d6d8..04c3d40 100644 --- a/src/main/io/uuddlrlrba/ktalgs/datastructures/PriorityQueue.kt +++ b/src/main/io/uuddlrlrba/ktalgs/datastructures/PriorityQueue.kt @@ -26,10 +26,14 @@ import io.uuddlrlrba.ktalgs.sorts.exch import java.util.* import kotlin.Comparator -class PriorityQueue(size: Int, val comparator: Comparator? = null) : Collection { +class PriorityQueue(capacity: Int, val comparator: Comparator? = null) : Collection { public override var size: Int = 0 private set - private var arr: Array = Array?>(size, { null }) as Array + private var arr: Array = Array?>(capacity, { null }) as Array + + init { + if (capacity <= 0) throw Error("Invalid capacity: $capacity") + } public fun add(element: T) { if (size + 1 == arr.size) {