From 9b30dae91b8f29ce69e7c1e770eff387abdfc6ad Mon Sep 17 00:00:00 2001 From: Sihat Afnan <57033114+AfnanCSE98@users.noreply.github.com> Date: Sun, 8 Nov 2020 23:50:54 +0600 Subject: [PATCH] Update BinomialHeaps.cpp You missed two cases in deleteMin. when the minPtr has no sibling before or after i.e. there is only a single tree in the heap and when minPtr is the head of the heap and it has at least one sibling(i.e. there are multiple trees) --- data-structures/binomial-heaps/BinomialHeaps.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/data-structures/binomial-heaps/BinomialHeaps.cpp b/data-structures/binomial-heaps/BinomialHeaps.cpp index 7843ecc..6799fa3 100644 --- a/data-structures/binomial-heaps/BinomialHeaps.cpp +++ b/data-structures/binomial-heaps/BinomialHeaps.cpp @@ -376,6 +376,10 @@ class BinomialHeap { prevMin->sibling = minPtr->sibling; } else if (prevMin != nullptr && minPtr->sibling == nullptr) { prevMin->sibling = nullptr; + }else if(prevMin == nullptr and minPtr->sibling != nullptr) { + head = minPtr->sibling; + }else if(prevMin == nullptr and minPtr->sibling == nullptr) { + head = nullptr; } // remove parent reference from all its child @@ -427,4 +431,4 @@ int main() { heap1.deleteMin(); heap1.printHeap(); return 0; -} \ No newline at end of file +}