c++将单向链表封装成类,求纠错

2025-02-24 05:34:21
推荐回答(2个)
回答1:

Node* LinkList::getinsertPos(char c) {   //找该字母前一个节点的位置
Node* pos;
if (head->data>c || head == NULL) // 运行这句程序就崩溃了。首先head如果等于NULL,那么就不可以调用head->data,其他的暂时没看。到这就卡住了。
pos = NULL;
else {
Node* tmp = head;
while (tmp->next != NULL) {
if (tmp->next->data>c)
pos = tmp;
else
tmp = tmp->next;
}
if (tmp->next == NULL)
pos = tmp;
}
return pos;
}

回答2:

这种东西需要自己调试的,靠肉眼看出错误是很难的