解题思路:声明一个结构体类型,其成员包括num(学号),score(得分),next(指针变量)。将第一个结点的地址赋给头指针head,将第二个结点的起始地址赋给第一个节点的next成员,将第三个结点的起始地址赋给第二个节点的next成员。第三个结点的next成员赋给null
#include<stdio.h>
struct Student{
int num;
float score;
struct Student * next;
};
int main(){
struct Student a,b,c,*head,*p;
a.num= 10101;a.score= 89.5;
b.num= 10103;b.score= 92.4;
c.num= 10105;c.score= 96.0;
head = &a;
a.next = &b;
b.next = &c;
c.next = NULL;
p = head;
do{
printf("%ld%5.1f\n",p->num,p->score);
p = p->next;
}while(p!=NULL);
return 0;
}
该程序定义了一个结构体类型,包含学号(num)、得分(score)和指向下一个节点的指针(next)。然后创建了三个节点并连接成一个简单的链表,头节点为a,并通过遍历打印链表中的所有节点信息。
755

被折叠的 条评论
为什么被折叠?



