So here we have the remove min heap function.
There's different ways to implement this, but this is just a simple two-line way.
So, first what we do is we pop the last element from the list,
and then we replace that by putting it in the position of the first element.
This effectively removes the minimum element.
And then the only other thing we have to do is run down-heapify on the first element
to make sure we maintain the heap property.
So, as a simple example, if we just wrote
apply or remove min heap function to this heap,
what it will do is it will take the last element here
and move it up to the top, removing the minimum element.
Then all we have to do is apply the down-heapify function.
So what we do is
we swap the 4 and the 1 here, and then we swap the 4 and the 3.
That's the remove min heap function.
यहाँ तो हम निकालें मिन ढेर समारोह है।
वहाँ अलग अलग तरीके से यह लागू करने के लिए है, लेकिन यह सिर्फ एक सरल दो-लाइन तरीका है।
तो, सबसे पहले हम क्या हम पॉप है पिछले तत्व सूची से,
और फिर हम कि जगह यह पहला तत्व की स्थिति में डाल द्वारा।
यह प्रभावी रूप से कम से कम तत्व निकाल देता है।
और फिर केवल दूसरी बात हम करने के लिए है चला है डाउन-heapify पर पहले तत्व
यह सुनिश्चित करने के लिए हम ढेर संपत्ति को बनाए रखने।
तो, एक सरल उदाहरण के लिए, के रूप में यदि हम सिर्फ लिखा था
लागू करें या निकालें मिन ढेर समारोह इस ढेर को,
यह क्या होगा है यह पिछले तत्व यहाँ ले जाएगा
और यह ऊपर से ऊपर कम से कम के तत्व को हटाने, ले जाएँ।
हम सभी को यह करना है तो लागू डाउन heapify-समारोह।
तो हम क्या है
हम 4 और यहाँ 1 स्वैप, और फिर हम 4 और 3 स्वैप।
कि निकालें मिन ढेर समारोह है।
ここにremove_min_heap関数があります
いろいろな方法がありますが
これは数行の簡単な方法です
まず最初にリストから最後の要素を取り出します
これを最初にある要素の位置に置き換えます
実質的に最小値の要素を除きました
次にヒーププロパティを維持できるように
最初の要素をdown_heapifyします
簡単な例を使って
remove_min_heap関数を適用してみます
この最後の要素を取り出し
一番上に動かし一番上の要素を取り除きます
次にdown_heapify関数を適用します
4と1を置き換え次に4と3を置き換えます
これがremove_min_heap関数です