一个单向链表的程序

发表于:2007-05-25来源:作者:点击数: 标签:程序单向链表一个
一个单向链表的程序 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(
一个单向链表的程序

      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 }

原文转自:http://www.ltesting.net

评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)