Skip to content

Commit

Permalink
Fix BinaryHeap
Browse files Browse the repository at this point in the history
  • Loading branch information
vadyushkins committed Feb 15, 2024
1 parent d0bb192 commit 9cb6aea
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions algorithms/binary_heap/binary_heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,22 @@ struct BinaryHeap {
}

void remove(size_t key) {
std::swap(
this->container->begin()[key],
this->container->begin()[this->container->size() - 1]
);
this->container->pop_back();
this->sift_down(key);
if (this->container->size() > key) {
std::swap(
this->container->begin()[key],
this->container->begin()[this->container->size() - 1]
);
this->container->pop_back();
this->sift_down(key);
}
}

void pop() {
this->del(0);
}

void change(size_t key, T new_value) {
if (this->container->begin()[key] != new_value) {
if (this->container->size() > key && this->container->begin()[key] != new_value) {
this->container->begin()[key] = new_value;
if (
key > 0 &&
Expand Down

0 comments on commit 9cb6aea

Please sign in to comment.