O(n)
O(nlogn)
()*i ()r[j]key>r[j+]key ()true ()r[j] ()*i
()*i ()j<=r ()j←j+ ()xkey>heap[j]key ()i←j ()j←*i ()x
()j:=*i ()finished:=false ()(r[j]key>r[j+]key) ()r[i]:=r[j] ()i:=j () j:=*i ()r[i]:=t; ()sift(rin) ()r[]:=r[i] ()sift(ri)
④是堆 ()選擇 ()篩選法 ()O(nlogn) ()O()
() 選擇 ()完全二叉樹 ()O(NlogN) ()O() ()滿足堆的性質
()finish:=false ()h[i]:=h[j]; i:=j; j:=*j; ()h[i]:=x ()hkn ()sift(hr)
{DQFXAPBNMYCW}
()p[k]:=j ()i:=i+ ()k= ()m:=n ()m<n ()a[i]:=a[m] ()a[m]:=t
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
From:http://tw.wingwit.com/Article/program/sjjg/201311/23210.html