Skip to content

test 2#11

Merged
cutenti merged 1 commit intomainfrom
Test/2
Dec 19, 2025
Merged

test 2#11
cutenti merged 1 commit intomainfrom
Test/2

Conversation

@cutenti
Copy link
Owner

@cutenti cutenti commented Dec 12, 2025

No description provided.

Copy link

@Godrik0 Godrik0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • -10 баллов за отсутствие extractMin
  • -8 баллов за merge
  • -4 балла за insert и get_minimum
    Итого 8/30

return self
result = None
curr = None
p1 = self
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Должно быть 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это не выполняет 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:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У Вас в NodeHeap не было поля key

new_heap = Heap()
new_node = NodeHeap(key, value)
new_heap.head = new_node
self.merge(new_heap)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В merge возвращается результат, но не обновляется текущая куча, из-за этого, и того что insert игнорирует то, что возвращает merge, вставка новых элементов не будет работать.

@cutenti cutenti merged commit f13a723 into main Dec 19, 2025
2 checks passed
@cutenti cutenti deleted the Test/2 branch December 19, 2025 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants