mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-28 12:52:57 +08:00
build
This commit is contained in:
@ -240,9 +240,9 @@ It's worth mentioning that **since leaf nodes have no children, they naturally f
|
||||
}
|
||||
|
||||
/* 元素入堆 */
|
||||
fun push(value: Int) {
|
||||
fun push(_val: Int) {
|
||||
// 添加节点
|
||||
maxHeap.add(value)
|
||||
maxHeap.add(_val)
|
||||
// 从底至顶堆化
|
||||
siftUp(size() - 1)
|
||||
}
|
||||
@ -270,11 +270,11 @@ It's worth mentioning that **since leaf nodes have no children, they naturally f
|
||||
// 交换根节点与最右叶节点(交换首元素与尾元素)
|
||||
swap(0, size() - 1)
|
||||
// 删除节点
|
||||
val value = maxHeap.removeAt(size() - 1)
|
||||
val _val = maxHeap.removeAt(size() - 1)
|
||||
// 从顶至底堆化
|
||||
siftDown(0)
|
||||
// 返回堆顶元素
|
||||
return value
|
||||
return _val
|
||||
}
|
||||
|
||||
/* 从节点 i 开始,从顶至底堆化 */
|
||||
|
@ -1183,9 +1183,9 @@ Given a total of $n$ nodes, the height of the tree is $O(\log n)$. Hence, the lo
|
||||
|
||||
```kotlin title="my_heap.kt"
|
||||
/* 元素入堆 */
|
||||
fun push(value: Int) {
|
||||
fun push(_val: Int) {
|
||||
// 添加节点
|
||||
maxHeap.add(value)
|
||||
maxHeap.add(_val)
|
||||
// 从底至顶堆化
|
||||
siftUp(size() - 1)
|
||||
}
|
||||
@ -1735,11 +1735,11 @@ Similar to the element insertion operation, the time complexity of the top eleme
|
||||
// 交换根节点与最右叶节点(交换首元素与尾元素)
|
||||
swap(0, size() - 1)
|
||||
// 删除节点
|
||||
val value = maxHeap.removeAt(size() - 1)
|
||||
val _val = maxHeap.removeAt(size() - 1)
|
||||
// 从顶至底堆化
|
||||
siftDown(0)
|
||||
// 返回堆顶元素
|
||||
return value
|
||||
return _val
|
||||
}
|
||||
|
||||
/* 从节点 i 开始,从顶至底堆化 */
|
||||
|
Reference in New Issue
Block a user