单链表的基本操作实验报告

单链表的基本操作实验报告

ID:38416093

大小:42.00 KB

页数:3页

时间:2019-06-12

单链表的基本操作实验报告_第1页
单链表的基本操作实验报告_第2页
单链表的基本操作实验报告_第3页
资源描述:

《单链表的基本操作实验报告》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、课程名称:数据结构与算法成绩评定:湖南第一师范学院信息科学与工程系实验报告实验项目名称:单链表的基本操作指导教师:学生姓名:沈丽桃学号:10403080118专业班级:10教育技术实验项目类型:验证实验地点:科B305实验时间:2011年10月20日一、实验目的与要求:实验目的:实现线性链表的创建、查找、插入、删除与输出。基本原理:单链表的基本操作二、实验环境:(硬件环境、软件环境)1.硬件环境:奔ⅣPC。2.软件环境:WindowsXP操作系统,TC2.0或VC++。三、实验内容:(原理、操作步骤、程序代码等)#include#inclu

2、de#includestructcelltype{intelement;structcelltype*next;};typedefintposition;voidmain(){structcelltype*head,*p;intx,choice;voidINSERT(intx,structcelltype*p);voidLOCATE(intx,structcelltype*p);voidDELETE(intx,structcelltype*p);p=(structcelltype*)malloc(sizeof(stru

3、ctcelltype));head=p;p->element=0;p->next=NULL;printf(“Pleaseoption:1:Insert2:Locate3:Delete”);printf(“Pleasechoose:”);scanf(“%d”,&choice);switch(choice)case1:printf(“Pleaseinputanode:”);scanf(“%d”,&x);p=head;INSERT(x,p);for(p=head;p!=NULL;p=p->next)printf(“%d”,p->element);printf(

4、“”);break;case2:printf(“Pleaseinputthedatayouwanttolocate:”);scanf(“%d”,&x);p=head;LOCATE(x,p);break;case3:printf(“Pleaseinputthedatayouwanttodelete:”);scanf(“%d”,&x);DELETE(x,p);for(p=head;p!=NULL;p=p->next)printf(“%d”,p->next);printf(“”);break;}voidINSERT(intx,structcelltype*

5、p){structcelltype*t,*q;q=(structcelltype*)malloc(sizeof(structcelltype));q->next=x;while((x>p->element)&&(p!=NULL)){t=p;p=p->next;}if((x>p->element)&&(p->next!=NULL)){p->next=q;q->next=NULL;}else{q->next=p;t->next=q;}}voidLOCATE(intx,structcelltype*p){while(p->next!=NULL)if(p->next

6、->element==x)printf(“thenumber%disin%d”,x,p);elseprintf(“thenumbernotexist!”);}voidDELETE(intx,structcelltype*p){while((p->element!=x)&&(p->next!=NULL)){t=p;p=p->next;}if(p->element==x)t->next=p->next}errorC2018:unknowncharacter’Oxal’errorC2065:’Please’:undeclaredidentifiererro

7、rC4024:’printf’:differenttypesforformalandactualparameter1errorC4047:’function’:’const*differsinleversofindirectionfrom’int’errorC2146:syntaxerror:missing’)’beforeidentifier’option’errorC2017:illegalescapesequenceerrorC2059:syntaxerror:’)’errorC2143:syntaxerror:missing’)’before’%’出

8、现了很多错误,主要是因为printf里的一对双引号不

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。