链表——尾插法

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <malloc.h>
 4 typedef struct student
 5 {
 6     int num;
 7     float socre;
 8     struct student *next;
 9 }Student;
10 Student *creatlist(void)
11 {
12     Student *head,*pt;
13     head=pt=(Student *)malloc(sizeof(Student));
14     pt = head;
15     head->next=NULL;
16     Student *cur=(Student *)malloc(sizeof(Student));
17     int num;float socre;
18     scanf("%d,%f",&num,&socre);
19     while(num)
20     {
21         cur=(Student *)malloc(sizeof(Student));
22         cur->num=num;
23         cur->socre=socre;
24 
25         pt->next  = cur;
26         cur->next = NULL;
27         pt=cur;
28 
29         scanf("%d,%f",&num,&socre);
30     }
31     return head;
32 }
33 int main()
34 {
35     Student *head=creatlist();
36     head=head->next;
37     while(head)
38     {
39 
40         printf("num:%d,socre:%.f
",head->num,head->socre);
41         head=head->next;
42             
43     }
44     system("pause");
45 }
原文地址:https://www.cnblogs.com/huxiaobai/p/10199913.html