我很難搞清楚爲什麼我的刪除功能不起作用。這是一個布爾值,如果一個項目被刪除,它需要返回。任何幫助,將不勝感激從單個鏈接列表中刪除一個節點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