单链表的基本操作实验报告_第1页
单链表的基本操作实验报告_第2页
单链表的基本操作实验报告_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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

2、nt element; struct celltype*next; ; typedef int position; void main() struct celltype*head,*p; int x,choice; void insert(int x,struct celltype*p); void locate(int x,struct celltype*p); void delete(int x,struct celltype*p); p=(struct celltype*)malloc(sizeof(struct celltype); head=p; p-element=0; p-ne

3、xt=null; printf(“please option:1:insert 2:locate 3:deleten”); printf(“please choose:”); scanf(“%d ”,&choice); switch(choice) case 1: printf(“please input a node:”); scanf(“%d ”,&x); 湖南第一师范学院信息科学与工程系实验报告 p=head; insert(x,p); for(p=head;p!=null;p=p-next) printf(“ %d ”,p-element); printf(“n ”);

4、 break; case 2: printf(“please input the data you want to locate:”); scanf(“%d ”,&x); p=head; locate(x,p); break; case 3: printf(“please input the data you want to delete:”); scanf(“%d ”,&x); delete(x,p); for(p=head;p!=null;p=p-next) printf(“%d ”,p-next); printf(“n ”); break; void insert(int

5、 x,struct celltype*p) struct celltype*t,*q; q=(struct celltype*)malloc(sizeof(struct celltype); q-next=x; while(xp-element)&(p!=null) t=p; p=p-next; if(xp-element)&(p-next!=null) p-next=q; q-next=null; else q-next=p; t-next=q; void locate(int x,struct celltype*p) while(p-next!=null) if(p-nex

6、t-element=x) printf(“the number %d is in %dn”,x,p); else printf(“the number not exist!n” ); void delete(int x,struct celltype*p) while(p-element!=x)&(p-next!=null) t=p; p=p-next; if(p-element=x) t-next=p-next error c2018:unknown character oxalerror c2065:please :undeclared identifier error c4024

7、:printf:different types for formal and actual parameter 1 error c4047: function: const*differs in levers of indirection from int error c2146:syntaxerror:missing) before identifieroption error c2017:illegal escape sequence error c2059:syntax error:) error c2143:syntax error:missing) before % 出现了很多错误,

8、主要是因为printf里的一对双引号不是英文状态下的。将双引号改好后,错误消失,输入时应注意细节,最好直接在编译环境下输程序error c2043:illegal break error c2043:illegal case error c2198:scanf :too few actual parameters 这里是由于每一个case 间应有缩进,或者用大括号括起来。error c2065: t:undeclared identifier warning c4047:=: struct celltype*differs in levers of indirection 这个错误是p-next=x,应改为 p-element=x error c2223:left of-next must point to struct/union 这里是由于t 没有定义,还有最后一个语句后没有分号。四、实验体会注意细节,像拼写错误就该避免,要注意所有符号必须是英文状态下的。所有变量必须定义清楚,在用 switch 语句时,注意每个cas

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论