Update a comment in my_heap.
This commit is contained in:
parent
8a4a7aa219
commit
592e82818c
@ -24,7 +24,7 @@ func newHeap() *maxHeap {
|
|||||||
|
|
||||||
/* 构造函数,根据切片建堆 */
|
/* 构造函数,根据切片建堆 */
|
||||||
func newMaxHeap(nums []any) *maxHeap {
|
func newMaxHeap(nums []any) *maxHeap {
|
||||||
// 所有元素入堆
|
// 将列表元素原封不动添加进堆
|
||||||
h := &maxHeap{data: nums}
|
h := &maxHeap{data: nums}
|
||||||
for i := len(h.data) - 1; i >= 0; i-- {
|
for i := len(h.data) - 1; i >= 0; i-- {
|
||||||
// 堆化除叶结点以外的其他所有结点
|
// 堆化除叶结点以外的其他所有结点
|
||||||
|
@ -20,7 +20,7 @@ class MaxHeap {
|
|||||||
|
|
||||||
/* 构造函数,根据输入列表建堆 */
|
/* 构造函数,根据输入列表建堆 */
|
||||||
public MaxHeap(List<Integer> nums) {
|
public MaxHeap(List<Integer> nums) {
|
||||||
// 所有元素入堆
|
// 将列表元素原封不动添加进堆
|
||||||
maxHeap = new ArrayList<>(nums);
|
maxHeap = new ArrayList<>(nums);
|
||||||
// 堆化除叶结点以外的其他所有结点
|
// 堆化除叶结点以外的其他所有结点
|
||||||
for (int i = parent(size() - 1); i >= 0; i--) {
|
for (int i = parent(size() - 1); i >= 0; i--) {
|
||||||
|
@ -710,10 +710,10 @@ comments: true
|
|||||||
```go title="my_heap.go"
|
```go title="my_heap.go"
|
||||||
/* 构造函数,根据切片建堆 */
|
/* 构造函数,根据切片建堆 */
|
||||||
func newMaxHeap(nums []any) *maxHeap {
|
func newMaxHeap(nums []any) *maxHeap {
|
||||||
// 所有元素入堆
|
// 将列表元素原封不动添加进堆
|
||||||
h := &maxHeap{data: nums}
|
h := &maxHeap{data: nums}
|
||||||
|
// 堆化除叶结点以外的其他所有结点
|
||||||
for i := len(h.data) - 1; i >= 0; i-- {
|
for i := len(h.data) - 1; i >= 0; i-- {
|
||||||
// 堆化除叶结点以外的其他所有结点
|
|
||||||
h.siftDown(i)
|
h.siftDown(i)
|
||||||
}
|
}
|
||||||
return h
|
return h
|
||||||
|
Loading…
x
Reference in New Issue
Block a user