赞
踩
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <iostream>
- using namespace std;
- #define null 0
-
- //用单链表来存储
- struct studentgrade2
- {
- int no;
- char name[10];
- double score;
- studentgrade2 *next; //存放下一个节点指针
- };
- //建立一个用于存放高等数学成绩单的单链表(头节点地址为head)
- int main()
- {
- studentgrade2 * head; //head为学生单链表的开始节点
- studentgrade2 * p1,*p2,*p3,*p4;
- p1=new studentgrade2();
- p1->no=20771301;strcpy(p1->name,"张三");p1->score=90;
- p2=new studentgrade2();
- p2->no=20771302;strcpy(p2->name,"李四");p2->score=90;
- p3=new studentgrade2();
- p3->no=20771303;strcpy(p3->name,"王五");p3->score=90;
- p4=new studentgrade2();
- p4->no=20771304;strcpy(p4->name,"赵六");p4->score=90;
- head =p1; //开始节点用head标识
- p1->next=p2; p2->next=p3;p3->next=p4; //建立节点之间的关系
- p4->next=null; //尾节点的next域置为空
- cout<<p1->name<<endl;
- system("pause");
- return 0;
- }
-
-
-
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。