From 2cdf0884102fb02fcd94a65cf01d4150ead9f012 Mon Sep 17 00:00:00 2001 From: xiaok29 <1526783667@qq.com> Date: Thu, 20 Jun 2024 15:51:12 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20perf:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Delete unnecessary conditions --- codes/go/chapter_heap/my_heap.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codes/go/chapter_heap/my_heap.go b/codes/go/chapter_heap/my_heap.go index 1cc091b2f..c51ddb3ee 100644 --- a/codes/go/chapter_heap/my_heap.go +++ b/codes/go/chapter_heap/my_heap.go @@ -79,7 +79,7 @@ func (h *maxHeap) push(val any) { /* 从节点 i 开始,从底至顶堆化 */ func (h *maxHeap) siftUp(i int) { - for true { + for { // 获取节点 i 的父节点 p := h.parent(i) // 当“越过根节点”或“节点无须修复”时,结束堆化 @@ -114,7 +114,7 @@ func (h *maxHeap) pop() any { /* 从节点 i 开始,从顶至底堆化 */ func (h *maxHeap) siftDown(i int) { - for true { + for { // 判断节点 i, l, r 中值最大的节点,记为 max l, r, max := h.left(i), h.right(i), i if l < h.size() && h.data[l].(int) > h.data[max].(int) {