链表
来源:互联网 发布:成都瑞星数据恢复 编辑:程序博客网 时间:2024/06/05 18:35
链表:动态的进行存储分配的一种结构
节点包括:数据域 和指针域
p1指的是新建的节点,包括指针域和数据域。
#include<stdio.h>
#include<malloc.h>struct student{ long num; float score; struct student *next;};
int main(){
struct student *head,*p1,*p2;
int i,len;
len=sizeof(struct student);
p1=p2=(struct student*)malloc(len);
scanf("%ld,%f",&p1->num,&p1->score);
head = NULL;
while(p1->num!=0)
{
if(head==NULL)
head=p1;//头指针执行p1节点
else
{ p2->next=p1;//p1新开辟的节点链接到p2的后面
p2=p1;}
p1=(struct student*)malloc(len);
scanf("%ld,%f",&p1->num,&p1->score);
p2->next = NULL;
}
//输出链表数据
struct student *p;p=head;
do{
printf("%ld%5.1f\n",p->num,p->score);
p=p->next;
}while(p!=NULL);
return 0;
}
阅读全文
0 0
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 链表
- 2017济南北大青鸟accp和学士后课程的真实情况
- javaWeb中文件的上传与下载及乱码问题解决
- Android ScrollView的使用
- 处理Minimum supported Gradle version is 3.3. Current version is 2.14.1问题
- Eclipse高效率开发技巧
- 链表
- pta 两个有序链表序列的交集
- [2017纪中10-26]数论 结论题
- 最新JavaEE版本安装tomcat插件
- 微信开发学习总结(一)——微信开发环境搭建
- phpcms使用技巧
- Hibernate(1)---概述
- RPC 简单介绍
- 线程安全问题