来自 Introduction to Algorithms 的伪代码声明:
for each node w in the root list of H
link trees of the same degree
但是如何有效地为每个根节点部分实现?在整合过程中,原始根链接到相同程度的其他根,这使得很难仅通过根节点的循环列表。我如何判断是否检查了每个根节点?
答案 0 :(得分:0)
您可以这样做的一个简单方法是使用三个步骤:
以下是您执行每个步骤的方法:
打破循环链接:
rootList->prev->next = NULL;
rootList->prev = NULL;
迭代双重链表。
Node* current = rootList;
while (current != NULL) {
/* Cache the next node to visit so that even if the list changes, we can still
* remember where to go next.
*/
Node* next = current->next;
/* ... main Fibonacci heap logic ... */
current = next;
}
修复双向链表:
Node* curr = rootList;
if (curr != NULL) { // If list is empty, no processing necessary.
while (curr->next != NULL) {
curr = curr->next;
}
curr->next = rootList;
rootList->prev = curr;
}
希望这有帮助!