OSDN Git Service

Update binary-heap.md
authorAsurx <9735627709@qq.com>
Wed, 4 Sep 2019 03:00:46 +0000 (11:00 +0800)
committerGitHub <noreply@github.com>
Wed, 4 Sep 2019 03:00:46 +0000 (11:00 +0800)
将二叉堆上移、下移代码中的下移代码修正为大根堆对应代码

docs/ds/binary-heap.md

index cc6e612..6c2c712 100644 (file)
@@ -62,8 +62,8 @@ up(x) {
 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;
+    if (t + 1 <= n && h[t + 1] > h[t]) t++;
+    if (h[t] <= h[x]) break;
     swap(h[x], h[t]);
     x = t;
   }