我很难搞清楚为什么我的删除功能不起作用。这是一个布尔值,如果一个项目被删除,它需要返回。任何帮助,将不胜感激从单个链接列表中删除一个节点C
boolean delete(SLL *list, String str){
NODE *current, *previous,*temp;
temp=malloc(sizeof(Employee));
previous=NULL;
current = list -> head;
while(current->next!=NULL) {
if(strcmp(current->anEmployee->name, str) == 0){
if(current=list->head){
list->head=current->next;
}
if(previous->next == NULL){//item not found in list
return 0;
}
else { //current is to be deleted
temp->next=current->next;
previous->next=temp->next;
return 1;
}
}
}
什么不行呢? – 2012-04-13 20:01:02
if(current = list-> head){ 应该是==吗? – strkol 2012-04-13 20:01:53
也有你在函数中有内存泄漏,不需要临时变量 – strkol 2012-04-13 20:10:01