1 #include "head.h" 2 struct Student *del_same_age(struct Student*head, int age) 3 { 4 struct Student *p, *pt; int find = 0; 5 p = pt = head; 6 while (p != NULL)//当循环到最后一个节点时 7 { 8 9 if (p->stu_age == age)//如果相等 10 { 11 find++; //说明找到了 12 if (p == head)//如果找到是头结点 13 { 14 head = p->next; 15 p = p->next;//循环节点后移 16 pt = p; 17 } 18 else//如果不是头结点 19 { 20 pt->next = p->next; 21 p = p->next; 22 } 23 } 24 else//如果没有找到 25 { 26 pt = p; 27 p = p->next;//循环节点后移 28 } 29 } 30 if (!find)//如果循环下来没有找到节点 31 printf("not found %d", age); 32 return head; 33 }