这里是我到目前为止的代码:如何从链表中删除节点?
struct stockRecord {
int code;
char name[MAXNAMELEN];
struct stockRecord* next;
};
struct stockRecord* temp = NULL;
struct stockRecord* head = NULL;
struct stockRecord* prevptr = NULL;
struct stockRecord* resfun(struct stockRecord* list)
{
temp = list;
if (head == NULL) head = list;
if (temp == NULL) {
return head;
} else {
if (prevptr == NULL) { //first node
if (strstr(temp->name, "ABC-") != NULL) {
temp = temp->next; //remove the current node
}
}
prevptr = list;
if (temp->next == NULL) {
return head;
} else {
return resfun(temp);
}
}
}
我不知道如何删除一个节点,并重新连接相邻节点。然后我需要将头节点返回到主函数。
请任何人都可以帮忙吗?
谢谢。
你的代码与你的问题有什么关系? – 2011-06-05 12:30:23
我已经开始编辑你的问题,以便更清楚地说出我认为你在问什么......如果我错了,请随时加入并改正我,并请提前接受我的意见。现在,要回答... – corlettk 2011-06-05 12:40:27
真的应该开始使用局部变量! – 2011-06-05 12:42:00