一个单向链表的程序
1 #include <stdio.h>
2
3 int main(void)
4 {
5 struct student
6 {
7 char name[20];
8 int score;
9 struct student *next;
10 };
11 struct student s[5];
12 int i;
13 struct student *ptr;
14 for(i = 0; i < 5; i++)
15 {
16 printf("Please input name:");
17 scanf("%s",s[i].name);
18 printf("Please input score:");
19 scanf("%d",&s[i].score);
20 if(i != 4)
21 s[i].next = &s[i+1];
22 else
23 s[i].next = NULL;
24 }
25 ptr = &s[0];
26 while(ptr != NULL)
27 {
28 printf("name: %s score: %d\n",ptr->name,ptr->score);
29 ptr = ptr->next;
30 }
31 return 0;
32 }