电子科技大学软件技术基础实验2资料.doc

电子科技大学 通信与信息工程 学院 标 准 实 验 报 告 (实验)课程名称 软件技术基础实验 电子科技大学教务处制表 电 子 科 技 大 学 实 验 报 告 一、实验室名称: 校公共机房 二、实验项目名称:链表程序设计 三、实验学时:4学时 四、实验原理: 使用VS2010等C语言集成开发环境(IDE),在微型计算机上对程序进行编辑、编译、连接与运行。通过上机练习掌握在链表的建立、插入删除等方法和过程。 五、实验目的: 熟练链表的概念和基本操作方法。 掌握课程平台使用方法。 六、实验内容: 上机完成链表的一系列操作,并用链表完成课后习题9,编程实验,调试运行程序并完成报告。 七、实验器材(设备、元器件): 硬件要求:普通pc机,1G内存,100G硬盘空间即可。 软件要求:Windows 7,包括C编译器的IDE。 八、实验步骤、实验编程与运行结果: 程序文件名为***.cpp,源程序清单如下: /*基础实验1,链表的建立,插入,删除*/ #includestdio.h #includestdlib.h struct list { int info; struct list *next; }; struct list *Create(int *numnode) {//创建一个链表 struct list *head,*tail,*cnew; head=NULL; int num; printf(输入数据(以零结束):); while(1) { scanf(%d,num); if(num==0)//输入为零表示输入结束 break; cnew=(struct list*)malloc(sizeof(struct list)); cnew-info=num; cnew-next=NULL; if(head==NULL)//若为空则将头节点指向新节点 head=cnew; else tail-next=cnew;//将当前节点的next指向新的节点 tail=cnew; (*numnode)++; } return head; } void insert(struct list *h,int i,int x) { struct list *p,*t; int j; p=h; j=0; while(p!=NULLji-1) { p=p-next; j++; } if(j!=i-1) printf(overflow!); else { t=(struct list*)malloc(sizeof(struct list)); t-info=x; t-next=p-next; p-next=t; } } struct list *insert_head(struct list *h,int x) { struct list *p,*t; p=h; t=(struct list*)malloc(sizeof(struct list)); t-info=x; t-next=h; return t; } struct list *Delete_head(struct list *h) { struct list *p; p = h;h = h-next;free(p); return h; } void Delete(struct list *h,int i) { struct list *p,*s; int j; p=h; j=0; while(p-next!=NULLji-1) { p=p-next; j=j+1; } if(j!=i-1) printf(overflow!); else { s=p-next; p-next=p-next-next; free(s); } } void display(struct list *head) { struct list *p; if(head==NULL) { printf(链表为空,没有数据\n); return; } printf(\n链表的数据元素:\n); for(p=head;p!=NULL;p=p-

文档评论(0)

1亿VIP精品文档

相关文档