From 99438e045a41f18ba339ee8adccdcf7369e5c397 Mon Sep 17 00:00:00 2001 From: Ir1dXD Date: Thu, 5 Sep 2019 00:16:44 +0800 Subject: [PATCH] Update binary-heap.md --- docs/ds/binary-heap.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/ds/binary-heap.md b/docs/ds/binary-heap.md index 6c2c712a..43ec4266 100644 --- a/docs/ds/binary-heap.md +++ b/docs/ds/binary-heap.md @@ -53,18 +53,18 @@ auhor: HeRaNO, Xeonacid (伪代码) ```cpp -up(x) { +void up(x) { while (x > 1 && h[x] > h[x / 2]) { swap(h[x], h[x / 2]); x /= 2; } } -down(x) { +void down(x) { while (x * 2 <= n) { t = x * 2; if (t + 1 <= n && h[t + 1] > h[t]) t++; if (h[t] <= h[x]) break; - swap(h[x], h[t]); + std::swap(h[x], h[t]); x = t; } } @@ -80,8 +80,8 @@ down(x) { 从根开始,按 BFS 序进行。 -```text -build_heap_1() { +```cpp +void build_heap_1() { for (i = 1; i <= n; i++) up(i); } ``` @@ -96,8 +96,8 @@ build_heap_1() { 这时换一种思路,从叶子开始,逐个向下调整 -```text -build_heap_2() { +```cpp +void build_heap_2() { for (i = n; i >= 1; i--) down(i); } ``` -- 2.11.0