Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PriorityQueue.kt #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/main/io/uuddlrlrba/ktalgs/datastructures/PriorityQueue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ import io.uuddlrlrba.ktalgs.sorts.exch
import java.util.*
import kotlin.Comparator

class PriorityQueue<T>(size: Int, val comparator: Comparator<T>? = null) : Collection<T> {
class PriorityQueue<T>(capacity: Int, val comparator: Comparator<T>? = null) : Collection<T> {
public override var size: Int = 0
private set
private var arr: Array<T?> = Array<Comparable<T>?>(size, { null }) as Array<T?>
private var arr: Array<T?> = Array<Comparable<T>?>(capacity, { null }) as Array<T?>

init {
if (capacity <= 0) throw Error("Invalid capacity: $capacity")
}

public fun add(element: T) {
if (size + 1 == arr.size) {
Expand Down