实验二-线性表链式存储运算的算法实现(昆工版)_第1页
实验二-线性表链式存储运算的算法实现(昆工版)_第2页
实验二-线性表链式存储运算的算法实现(昆工版)_第3页
实验二-线性表链式存储运算的算法实现(昆工版)_第4页
实验二-线性表链式存储运算的算法实现(昆工版)_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

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

文档简介

昆明理工大学信息工程与自动化学院学生实验报告〔2023—2023学年第三学期〕课程名称:数据结构开课实验室:信自楼4442023年11月12日年级、专业、班计科122班学号202310405204姓名邹华宇成绩实验工程名称线性表链式存储运算的算法实现指导教师胡守成教师评语教师签名:年月日注:报告内容按实验须知中七点要求进行。主函数调用菜单函数调用创立函数主函数调用菜单函数调用创立函数调用插入函数调用删除函数调用输出函数程序结束1.掌握线性表链式存储结构的C语言描述及运算算法的实现;2.分析算法的空间复杂度和插入和删除的时间复杂度;3.总结比拟线性表顺序存储存储与链式存储的各自特点。程序功能:1.(菜单)主程序;2.链表的建立;3.链表的数据插入;4.链表的数据删除;5.链表的数据输出;二、实验原理及根本技术路线图〔方框原理图〕三、所用仪器、材料〔设备名称、型号、规格等〕联想计算机一台MicrosoftVisualc++6.0四、程序源代码#include<stdio.h>#include<conio.h>#include<malloc.h>#include<stdlib.h>typedefintdataType;typedefstructnode{dataTypedata;structnode*next;}linkList;linkList*createList(){intnum;linkList*head,*s,*r;head=NULL;r=NULL;printf("Enterthenumber(0tostop):");scanf("%d",&num);while(num!=00){s=(linkList*)malloc(sizeof(linkList));s->data=num;if(head==NULL)head=s;elser->next=s;r=s;printf("Enterthenumber(0tostop):");scanf("%d",&num);}if(r!=NULL)r->next=NULL;returnhead;}linkList*get(linkList*head,inti){intj;linkList*p;p=head;j=0;while((p->next!=NULL)&&(j<i)){p=p->next;j++;}if(i==j)returnp;elsereturnNULL;}linkList*locate(linkList*head,dataTypekey){linkList*p;p=head->next;while(p!=NULL){if(p->data!=key)p=p->next;elsebreak;}returnp;}voidinsertAfter(linkList*p,dataTypex){linkList*s;s=(linkList*)malloc(sizeof(linkList));s->data=x;s->next=p->next;p->next=s;}voidinsertBefore(linkList*p,dataTypex){linkList*s;s=(linkList*)malloc(sizeof(linkList));s->data=p->data;s->next=p->next;p->next=s;p->data=x;}voidinsert(linkList*L,dataTypex,inti){linkList*p;intj;j=i-1;p=get(L,j);if(p==NULL){printf("erro\n");getch();}else{insertAfter(p,x);printf("\nInsertSucceed");getch();}}voiddeleteAfter(linkList*p){linkList*r;r=p->next;p->next=r->next;free(r);}voidDelete(linkList*L,inti){intj;linkList*p;j=i-1;p=get(L,j);if(p!=NULL&&p->next!=NULL){deleteAfter(p);printf("\nDeleteSucceed");getch();}else{printf("error\n");getch();}}voiddisplay(linkList*head){inti=1;if(head==NULL){printf("EmptyList\n");}while(head!=NULL){printf("Index[%d]:%d\n",i,head->data);head=head->next;i++;}}charcaiDan(){charch;do{printf("1:CreateNewList\n");printf("2:Insert\n");printf("3:Delete\n");printf("4:Display\n");printf("5:Exit\n");printf("PleaseChoose:");}while(ch=getch(),ch!='1'&&ch!='2'&&ch!='3'&&ch!='4'&&ch!='5');returnch;}voidmain(){linkList*head=NULL;charch;inti,key;do{system("cls");ch=caiDan();printf("%c",ch);getch();printf("\n");switch(ch){case'1':head=createList();printf("Listwascreatedsuccessfully");getch();break;case'2':display(head);if(head==NULL){getch();break;}else{printf("\nInputKey:");scanf("%d",&key);printf("InputIndexuwanttoinsertafter:");scanf("%d",&i);insert(head,key,i);break;}case'3':display(head);if(head==NULL){getch();break;}else{printf("\nInputindexyouwanttodelete:");scanf("%d",&i);Delete(head,i-1);break;}case'4':display(head);getch();break;case'5':exit(0);}}while(ch!='5');

温馨提示

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

评论

0/150

提交评论