链表——尾插法
Posted huxiaobai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了链表——尾插法相关的知识,希望对你有一定的参考价值。
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 }
以上是关于链表——尾插法的主要内容,如果未能解决你的问题,请参考以下文章