Conversation
Godrik0
suggested changes
Dec 18, 2025
Godrik0
left a comment
There was a problem hiding this comment.
- -10 баллов за отсутствие
extractMin - -8 баллов за
merge - -4 балла за
insertиget_minimum
Итого 8/30
| return self | ||
| result = None | ||
| curr = None | ||
| p1 = self |
There was a problem hiding this comment.
Должно быть p1 = self.head, сейчас всё упадет
Comment on lines
+54
to
+65
| while p1 and p2: | ||
| if p1.degree <= p2.degree: | ||
| curr.sibling = p1 | ||
| p1 = p1.sibling | ||
| else: | ||
| curr.sibling = p2 | ||
| p2 = p2.sibling | ||
| curr = curr.sibling | ||
| if p1: | ||
| curr.sibling = p1 | ||
| else: | ||
| curr.sibling = p2 |
There was a problem hiding this comment.
Это не выполняет merge для двух куч. Нам нужно проходить по списку и объединять деревья одинаковой степени (если есть два дерева степени k, одно становится сыном другого, получается дерево степени k+1).
В алгоритме на вики за это отвечает эта часть кода
curH = H.head // объединение деревьев одной степени
while curH.sibling != null
if curH.degree == curH.sibling.degree
p[curH] = curH.sibling
tmp = curH.sibling
curH.sibling = curH.sibling.child
curH = tmp
continue
curH = curH.sibling
| min_node = self.head | ||
| cur = self.head.sibling | ||
| while cur: | ||
| if cur.key < min_node.key: |
| new_heap = Heap() | ||
| new_node = NodeHeap(key, value) | ||
| new_heap.head = new_node | ||
| self.merge(new_heap) |
There was a problem hiding this comment.
В merge возвращается результат, но не обновляется текущая куча, из-за этого, и того что insert игнорирует то, что возвращает merge, вставка новых элементов не будет работать.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.