1 #include"head.h"
 2 struct Student* del_same_ID(struct Student*p1, struct Student*p2)
 3 {
 4     struct Student *p0 = p1;
 5     struct Student *head_a  = p1;
 6     struct Student *head_b = p2;
 7     while (p1 != NULL)//终止条件是查询到a链表最后一个元素
 8     {
 9         p2 = head_b; //b链表总是从头指针开始循环
10         while ((strcmp(p1->ID, p2->ID) != 0) && (p2->next != NULL))//终止:要么找到相同元素,要//已经查询到b链表最后一个元素
11             p2 = p2->next;//每一个a链表的元素,都要对b 链表进行循环一遍
12         if ((strcmp(p1->ID, p2->ID) ==0))//如果查询到了
13         {
14             if (p1 == head_a)//当要删除的是头指针
15             {
16                 head_a = p1->next;//头指针后移一位
17                 p1 = p1->next;//p1指针后移
18             }
19             else//不是头指针
20             {
21                 p0->next = p1->next;//删除p1
22                 p1 = p0->next;//使得p0指向p1下一个节点
23             }
24             sum_a--;//
25         }
26         else//如果没找到
27         {
28             p0 = p1;//p1和p0都后移一位
29             p1 = p1->next;
30         }
31     }
32     return head_a;
33 }

 

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