数据结构 增加节点与查找节点

 1 //查找节点
 2 list* findNode(list *head, int num)//num:学号
 3 {
 4     list *ptr;
 5     ptr = head;
 6     while(ptr != NULL)
 7     {
 8         if (ptr->num == num)
 9             return ptr;
10         ptr = ptr->next;
11     }
12     return ptr;
13 }
14 //插入节点
15 list *insertNode(list *head, list *ptr, int num, int scort, char name[15])
16 {
17     list *inserNode = new list;
18     if (! inserNode)
19         return NULL;
20     inserNode->num = num;
21     inserNode->score = scort;
22     strcpy(inserNode->name , name);
23     inserNode->next = NULL;
24 
25     if (ptr == NULL)//第一个节点
26     {
27         inserNode->next = head;
28         return inserNode;
29     }
30     else
31     {
32         if (ptr->next == NULL)//如果是最后一个节点
33             ptr->next = inserNode;
34         else
35         {    //不是第一个, 也不是最后一个, 中间的
36             inserNode->next = ptr->next;
37             ptr->next = inserNode;
38         }
39     }
40     return head;
41 }
原文地址:https://www.cnblogs.com/moli/p/1434263.html