我正在尝试编写一个函数,该函数使用由邻接列表表示的图形进行一些计算,但我得到了一个我没有得到的分段错误错误。基本上我首先“删除”一个节点,然后再次重新插入它。这是我的代码:
int AdjList::bruteForce (node** list) {
int pointerIndex;
node* help;
node* help2;
for (int i=0; i<boundary; i++) {
huidigScore = 0;
help2 = list[i];
help = help2;
help2 = help2->next;
while (help2->next != NULL) {
help->next = help2->next;
help2->next = NULL;
pointerIndex = help2->number;
help2->next = help->next;
help->next = help2;
help2 = help2->next;
}
}
}
和列表初始化:
node** list;
node* help;
node* help2;
list = new node*[boundary];
for (int i=0; i<boundary; i++) {
list[i] = new node;
help = list[i];
help->next = NULL;
help->number = 0;
}
提前致谢。