有一链式结构定义如下 :struct stuchar name20;int no;struct stu next;;创建一个函数mydelpname删除链表中name域为name的结点返回链表的头指针。如果中p链表中结点的name域与name相同删除结点并返回头指针如果没找到在函数中显示没有找到返回头指针。程序中create函数已经为我们创建了一个有10个结点 的无头结点的链表。函数接口定义:在这
struct stu * mydel(struct stu *head,char *name){ struct stu *p,*q; p=head; if(strcmp(p->name,name)==0){ //头结点就是需要删除的节点 head=head->next; free(p); return head; } while(p->next!=NULL&&strcmp(p->next->name,name)!=0){ //查找需要删除的节点 p=p->next; } if(p->next==NULL){ //没找到 printf("no found\n"); return head; } q=p->next; //找到了要删除的节点 p->next=q->next; free(q); return head; }
原文地址: https://www.cveoy.top/t/topic/cFHl 著作权归作者所有。请勿转载和采集!