下面的代码是一个简单的静态链表,它是由3个学生的数据组成的(学号,成绩)的结点组成。
#include<iostream>
#include<stdio.h>
using namespace std;
struct student
{
long num;
float score;
struct student * next; //该指针指向student类型的结构体
}; //必须有分号
int main()
{
struct student a,b,c,*head,*p;
a.num=16010; a.score=89.5; //赋值
b.num=16011; b.score=98;
c.num=16012; c.score=94;
head=&a; //将a的地址给head
a.next=&b;
b.next=&c;
c.next=NULL;
p=head;
do //输出记录
{
cout<<p->num<<" "<<p->score<<endl;
p=p->next;
}while(p!=NULL);
getchar();
}