heapOf

fun <T> heapOf(vararg values: T, fn: SortTest<T>): Heap<T>

Creates a new heap containing the given values, sorted by the given SortTest function.

Example:

// Max heap
val heap = heapOf(1, 2, 3) { a, b -> a b }

heap.next() // 3
heap.next() // 2
heap.next() // 1

Return

A new Heap instance containing the given values.

Author

Elizabeth Paige Harper - https://github.com/foxcapades

Since

0.1.0

Parameters

values

Values to insert into the created Heap

fn

SortTest function to use to maintain the heap.


fun <T> heapOf(values: Iterable<T>, fn: SortTest<T>): Heap<T>

Creates a new heap containing the values in the given iterable, sorted by the given SortTest function.

Example:

val items = listOf(1, 2, 3)
val heap = heapOf(items) { a, b -> a b }

heap.next() // 3
heap.next() // 2
heap.next() // 1

Return

A new Heap instance containing the given values.

Author

Elizabeth Paige Harper - https://github.com/foxcapades

Since

0.1.0

Parameters

values

Values to insert into the created Heap

fn

SortTest function to use to maintain the heap.