clean up code
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Raffaele Mignone 2019-04-13 19:16:42 +02:00
parent a9bd9df609
commit 079723937d
Signed by: norangebit
GPG Key ID: F5255658CB220573
2 changed files with 5 additions and 15 deletions

View File

@ -57,16 +57,8 @@ class BinaryHeap<T> private constructor(
return result.toOption()
}
private fun print() {
print("|")
array.forEach {
print(" $it |")
}
println()
}
override fun peek(): Option<T> = if (size >= 1)
array[1].toOption()
array[FIRST_ELEMENT].toOption()
else
None
@ -84,7 +76,6 @@ class BinaryHeap<T> private constructor(
exchange(array, k / WAY, k)
pushUp(array, k / WAY)
}
else -> return
}
}
@ -109,9 +100,8 @@ class BinaryHeap<T> private constructor(
}
private fun exchange(array: Array<T?>, i: Int, j: Int) {
array[i] = array[j].also {
array[j] = array[i]
}
array[i] = array[j]
.also { array[j] = array[i] }
}
private fun isFull(): Boolean = size + 1 == array.size

View File

@ -60,8 +60,8 @@ object OrderedListSorter {
fun <T : Comparable<T>> sort(vararg lists: List<T>): List<T> {
val heap = BinaryHeap.createMinPriorityQueue<Node<T>, T> { it.value }
lists.forEachIndexed { index, list ->
heap.insert(Node(list.first(), index, 0))
lists.forEachIndexed { k, list ->
heap.insert(Node(list.first(), k, 0))
}
val outList = ArrayList<T>()