标签:单链表 lse struct head data 出现 turn ext span
起初我是这么写的:
struct node * deletenode(struct node *head,int b){ struct node *pre,*cur; pre=NULL; cur=head; if(head&&head->data==b){ head=head->next; free(cur); } else{ while(cur->data!=b){ pre=cur; cur=cur->next; } pre->next=cur->next; free(cur); } return head; }
结果提交时说段错误,改成下面这样就通过了,暂时还不知道为啥。。。
struct node * deletenode(struct node *head,int b){ struct node *pre,*cur; pre=NULL; cur=head; if(head&&head->data==b){ head=head->next; free(cur); } else{ while(cur){ if(cur->data==b){ pre->next=cur->next; free(cur); } pre=cur; cur=cur->next; } return head; } }
标签:单链表 lse struct head data 出现 turn ext span
原文地址:https://www.cnblogs.com/littleLittleTiger/p/11523281.html