静态链表,它由3个学生数据的结点组成,要求输出各结点中的数据。

#include <stdio.h> 
struct Student
{ int num;
   float score;
};
struct Node
{
 struct Student stu;
 struct Node *next; 
};
int main()
{ struct Node a,b,c,*head,*p;   
   a.stu. num=10101;  a.stu.score=89.5;   
   b.stu. num=10103;  b.stu.score=90;        
   c.stu .num=10107;  c.stu.score=85;   
   head=&a;           a.next=&b;   
   b.next=&c;         c.next=NULL;   
   p=head;   
   do        
   {printf("%ld%5.1f\n",p->stu.num,p->stu.score);
     p=p->next;   
  }while(p!=NULL);   
   return 0;
}


结果显示
10101 89.5
10103 90.0
10107 85.0
注意:
struct Student
{ int num;
   float score;
};
struct Node
{
 struct Student stu;
 struct Node *next; 
};
可以改写为下面的格式
struct Student
{ int num;
   float score;
   struct Student *next;
};
发布了195 篇原创文章 · 获赞 76 · 访问量 6970

猜你喜欢

转载自blog.csdn.net/qq_45696288/article/details/105269331