电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

线性表的基本操作

线性表的基本操作_第1页
1/15
线性表的基本操作_第2页
2/15
线性表的基本操作_第3页
3/15
实验二 线性表的基本操作一、实验目的1.掌握用 C++/C 语言调试程序的基本方法。2.掌握线性表的顺序存储和链式存储的基本运算,如插入、删除等.二、实验要求1.C++/C 完成算法设计和程序设计并上机调试通过.2.撰写实验报告,提供实验结果和数据。3. 分析算法,要求给出具体的算法分析结果,包括时间复杂度和空间复杂度,并简要给出算法设计小结和心得。三、实验内容:1。 分析并运行以下各子程序的主要功能。 程序 1:顺序存储的线性表和运算#include#define MAXSIZE 100int list[MAXSIZE];int n;/*insert in a seqlist*/int sq_insert(int list[], int *p_n, int i, int x){int j;if (i〈0 || i>*p_n) return(1);if (*p_n==MAXSIZE) return(2);for (j=*p_n+1; j〉i; j——)list[j]=list[j-1];list[i]=x;(*p_n)++;return(0);}/*delete in a seq list*/int sq_delete(int list[], int *p_n, int i){int j;if (i〈0 || i>=*p_n) return(1);for (j = i+1; j〈=*p_n; j++)list[j-1] = list[j];(*p_n)—-;return(0);} void main(){int i,x,temp;printf(”please input the number for n\n”);printf("n=”);scanf("%d",&n);for (i=0; i<=n; i++){printf(”list[%d]=",i); scanf(”%d",&list[i]);} printf(”The list before insertion is\n”);for (i=0; i<=n; i++) printf(”%d ",list[i]);printf(”\n”);printf ( ” please input the position where you want to insert a value\nposition=”);scanf(”%d",&i);printf(”please input the value you want to insert。\nx=");scanf("%d”,&x);temp=sq_insert(list,&n,i,x);switch(temp){case 0:printf(”The insertion is successful!\n");printf(”The list is after insertion is\n”);for(i=0; i〈=n; i++) printf(”%d ",list[i]);printf(”\n");printf("%d\n”,n);break;case 1:case 2:printf(”The insertion is not successful!\n”);break;}/*deleting*/printf("The list before deleting is\n");for (i=0; i<=n; i++) printf("%d ”,list[i]);printf(”\n");printf(”please input the position where you want to ...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

线性表的基本操作

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部