1 #include "head.h"
 2 struct Student*del(struct Student*head,char num[N])
 3 {
 4     struct Student*p1, *p2;
 5     if (head == NULL)                  //若链表为空,则无需处理
 6     {
 7         printf("\nlist NULL!\n");
 8         return (head);
 9     }
10     p2 = p1 = head;
11     while (strcmp(num, p1->nun) != 0 && p1->next != NULL)//重要!循环终止的条件是找到
12 //了要删除的节点或者搜寻到了最后一个节点
13     {
14         p2 = p1;         //循环中若,没找到,则指针往后移一位
15         p1 = p1->next;
16     }
17     if (strcmp(num, p1->nun) == 0)   //循环结束分两种情况,1是找到,找到也分两种情况
18     {
19         if (p1 == head) head = p1->next;   //第一个节点就是我们要找到
20         else    p2->next = p1->next;         //除第一节点外的处理方式(包括末尾节点)    
21         printf("delete:%s\n", p1->nun);
22         n--;       //删除一个就要成员数减一个;
23     }
24     else printf("%s not been found!\n", num);     //2,没找到怎完事
25     return head;
26 }

 

posted on 2016-12-23 22:13  新爱代  阅读(415)  评论(0编辑  收藏  举报