查看文章 |
简单静态链表实例
2009-03-03 21:04
#define NULL 0 #include<iostream> using namespace std; struct student { long num; float score; struct student *next; }; int main() { student a,b,c,*head,*p; a.num=31001;a.score=89.5;//对各结点的num和score成员赋值 b.num=31003;b.score=90; c.num=31007;c.score=85; head=&a;//将结点a的起始地址赋给头指针head a.next=&b;//将结点b的起始地址赋给a结点的next成员 b.next=&c; c.next=NULL;//此结点的next成员不存放其他结点地址 p=head;//使得p指针指向a结点 do { cout<<p->num<<" "<<p->score<<endl;//输出p指向的结点的数据 p=p->next;//使得p指向下一个结点 }while(p!=NULL);//输出完c结点后p的值为NULL故而退出while循环 return 0; } |
最近读者:
本篇日志被作者设置为禁止发表新评论