struct node {
struct node *next;
int data;
} *head;
将元素插入链表后,我正在使用此删除功能删除链表的元素,但程序卡住了。我不知道哪里出错了。请帮我。
void delete(int num1) {
struct node *del ,*prev_node;
del = head;
if(del == NULL) {
printf("\n The list is empty,cant delete element");
} else {
while(del != NULL) {
if(del->data == num1) {
if(del == head) {
head = del->next;
free(del);
} else {
prev_node->next = del->next;
free(del);
}
} else {
prev_node = del;
del = del->next;
}
}
}
}