建立简单的动态链表
#include <stdio.h>struct student
{
int num;
float score;
struct student *next;
};
int main()
{
struct student a,b,c,*head,*p;
a.num = 1;a.score = 98.5;
b.num = 2;b.score = 99.5;
c.num = 3;c.score = 97.5;
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;
}
页:
[1]