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

线性表的插入和删除C++程序VIP免费

线性表的插入和删除C++程序_第1页
1/9
线性表的插入和删除C++程序_第2页
2/9
线性表的插入和删除C++程序_第3页
3/9
修改内容:重新排版 《数据结构》试验报告 -------------线性表的插入和删除 康一飞 地理信息系统 08-2 08014208 一,实验目的 掌握线性表的顺序存储结构的定义及C语言实现插入,删除操作 掌握线性表的链式存储结构的定义及C语言实现插入,删除操作 二,实验内容 1 定义 数据元素之间的关系在计算机中又两种不同的表示方式:顺序映像和非顺序映像,由此得到两种不同的存储结构:顺序存储结构和链式存储结构。 顺序映像的特点是借助元素在存储器中的相对位置来表示数据元素之间的逻辑关系 非顺序映像的特点是借助指针元素存储地址的指针表示数据元素之间的逻辑关系 2 顺序表的插入 #include #include typedef struct { int elem; int length; int listsize; }SqList,* SqL; SqL CreateList_S() { int n; SqList *p,*S; S=(SqL) malloc (sizeof(SqList)); S->listsize=100; printf("input the length of the list:"); scanf("%d",&(S->length)); printf("input the element of the list:"); for(n=1,p=S;n<=(S->length);n++,p+=sizeof(SqList)) scanf("%d",&p->elem); return(S); } SqL ListInsert_S(SqL S) { int e,i,m,n; loop: printf("input the place you want to insert:"); scanf("%d",&i); if(i<1||i>S->length+1) { printf("ERROR input again\n"); goto loop; } printf("iuput the element you want to insert:"); scanf("%d",&e); m=S->length; for(n=i;n<=S->length;n++) { (S+m*sizeof(SqList))->elem=(S+(m-1)*sizeof(SqList))->elem; m=m-1; } (S+(i-1)*sizeof(SqList))->elem=e; S->length++; return(S); } void main() { SqList *Sa,*p; int n,i,e; Sa=CreateList_S(); printf("the list is:"); for(n=1,p=Sa;n<=(Sa->length);n++,p+=sizeof(SqList))printf("%d ",p->elem); printf("\n\n"); Sa= ListInsert_S(Sa); printf("the list is:"); for(n=1,p=Sa;n<=(Sa->length);n++,p+=sizeof(SqList))printf("%d ",p->elem); printf("\n"); } 3 单链表的删除 #include #include #define NULL 0 typedef struct LNode { int data; struct LNode *next; }LNode,*LiL; LiL CreatList_L() { int i,n; LNode *p,*L; L=(LiL)malloc(sizeof(LNod...

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

碎片内容

线性表的插入和删除C++程序

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