建立三个学生的单链表试试感觉
2014-08-29 22:26
281 查看
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define LEN sizeof(struct student)
struct student
{
long num;
float score;
struct student
*next;
};
int n;
struct student* creat(void)
{
struct student
*head;
struct student
*p1,*p2;
n = 0;
p1 = p2 =(struct student
*)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
head = NULL;
while(p1->num!=0&&n<3)
{
n=n+1;
if(n==1) head = p1;
else p2->next = p1;
p2 = p1;
p1 =(struct student *)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
}
p2->next
= NULL;
return head;
}
int main()
{
struct student
*head,*p;
p = head =
creat();
while(p!=NULL)
{
printf("%ld,%f\n",p->num,p->score);
p = p->next;
}
return 0;
}
#include <stdlib.h>
#include <malloc.h>
#define LEN sizeof(struct student)
struct student
{
long num;
float score;
struct student
*next;
};
int n;
struct student* creat(void)
{
struct student
*head;
struct student
*p1,*p2;
n = 0;
p1 = p2 =(struct student
*)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
head = NULL;
while(p1->num!=0&&n<3)
{
n=n+1;
if(n==1) head = p1;
else p2->next = p1;
p2 = p1;
p1 =(struct student *)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
}
p2->next
= NULL;
return head;
}
int main()
{
struct student
*head,*p;
p = head =
creat();
while(p!=NULL)
{
printf("%ld,%f\n",p->num,p->score);
p = p->next;
}
return 0;
}
相关文章推荐
- 建立一个简单的链表,它由三个学生数据的结点组成输出各节点中的数据。
- 例 9.8 建立一个如图9.9所示的简单链表,它由3个学生数据的结点组成,要求输出各结点中的数据。
- c语言:写一个函数建立一个有3名学生数据的单向动态链表
- 一个链表程序,支持建立,插入,删除,输出;学生的学号和分数
- 链表基础与解析//建立一个拥有3个学生数据的动态链表
- 建立一个链表存放学生信息并打印信息
- 建立学生信息链表
- PTA 4-1 建立学生信息链表 (50分)
- c语言:写一个函数建立一个有3名学生数据的单向动态链表
- 建立学生信息链表
- 用链表建立学生健康系统
- 【链表】 建立学生链表(student.cpp)
- 【暂无】 链表 建立学生链表(student.cpp)
- 建立学生信息链表
- 6-4 建立学生信息链表(20 分)——尾插建链表_题程序访问是越界——真是醉了,你自己跑下是会抛出异常的
- 【C++】建立一个学生信息链表,每个结点包括:学号、姓名、成绩。【原创技术】
- 单链表建立学生信息管理系统
- 编写程序:建立一个学生数据链表,每个节点的信息包括如下内容:学号,姓名,性别年龄专业。对链表做如下处理。输入一个学号(专业),如果链表中的节点包含此学号(专业),则删去该结点。
- 【C++】建立一个学生信息链表,每个结点包括:学号、姓名、成绩。【原创技术】
- 单链表的建立,测长度,打印,删除,插入,逆置c++代码实例及运行结果