数据结构实验指导书(电商)

上传人:人*** 文档编号:563801009 上传时间:2023-08-04 格式:DOCX 页数:21 大小:115.15KB
返回 下载 相关 举报
数据结构实验指导书(电商)_第1页
第1页 / 共21页
数据结构实验指导书(电商)_第2页
第2页 / 共21页
数据结构实验指导书(电商)_第3页
第3页 / 共21页
数据结构实验指导书(电商)_第4页
第4页 / 共21页
数据结构实验指导书(电商)_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《数据结构实验指导书(电商)》由会员分享,可在线阅读,更多相关《数据结构实验指导书(电商)(21页珍藏版)》请在金锄头文库上搜索。

1、WORD格式电子商务06-3吴锋刚数据构造实验指导书电子商务专业班级电子商务 06-3*吴锋刚学号09064280中国矿业大学管理学院2021年 1 月专业资料整理WORD格式数据构造专业资料整理WORD格式电子商务06-3吴锋刚实验一线性表的顺序表示和实现一、实验目的1、理解线性表的逻辑构造特性;2、熟练掌握线性表的顺序存储构造的描述方法,以及在该存储构造下的根本操作。二、实验内容实验 1.1用线性表的顺序存储构造实现十项根本操作:初始化、求长度、取元素、求前导、求后继、查找、插入、删除、判定空表、置空,生成sqlist.h 文件;编写 main 函数调用。【提示】 sqlist.h 文件的

2、代码实现线性表的顺序存储构造的根本操作;另建一个顺序表.cpp 文件实现main 函数,以用户交互的方式调用顺序表的各个功能。#includeprintf(Init List successfully!n);#include#includeelseconst MAXSIZE=100;printf(Init List unsuccessfully!n);typedef int datatype;typedef structvoid InsertList_sq(sqlist &L,int i,datatype e)datatype *elem;if(iL.length+1)int length;i

3、nt listsize;printf(i is error!n);sqlist;datatype *q,*p;void InitList_sq(sqlist &L,intq=&(L.elemi-1);maxsize=MAXSIZE)for(p=&(L.elemL.length-1);p=q;-q)L.elem=new datatypemaxsize;*(p+1)=*p;L.length=0;L.listsize=maxsize;*q=e;if(L.elem)/test if it successfulL.length+;专业资料整理WORD格式数据构造专业资料整理WORD格式电子商务06-3吴

4、锋刚void PrintList(sqlist &L)datatype *p,*q;p=&(L.elemi-1);int i,n;e=*p;n=L.length-1;q=L.elem+L.length-1;coutLength of Listfor(+p;p=q;+p)is :L.lengthendl;for(i=0;i=n;i+)*(p-1)=*p;coutL.elemiendl;L.length-;void DestoryList_sq(sqlist &L)int LocateElem_sq(sqlist &L,datatype e)delete L.elem;int i=1;L.list

5、size=0;datatype *p;L.length=0;p=L.elem;while(i=L.length)&(*p+!=e)#include sqlist.h#include i+;void main()if(i=L.length)sqlist L;InitList_sq(L);return i;char ch;datatype e;elseint i;ch=getchar();return 0;while(ch!=#)couti;coutinput a value:n;if(iL.length)cine;InsertList_sq(L,i,e);printf(Location of v

6、alue to bech=getchar();deleted is wrong !n);PrintList(L);专业资料整理WORD格式数据构造专业资料整理WORD格式电子商务06-3吴锋刚couti;finde;coutdelete elem is :eendl;coutLocation of elemPrintList(L);is :LocateElem_sq(L,e)endl;DestoryList_sq(L);PrintList(L);coutinput location of elem to bedeleted !endl;实验二线性表的链式表示和实现一、实验目的1. 理解线性表的

7、逻辑构造特性;2. 熟练掌握线性表的链表存储构造的描述方法,以及在该存储构造下的根本操作;并能灵活运用;3. 掌握双向链表和循环链表的的描述方法,以及在该存储构造下的根本操作。二、实验内容实验 2.1用线性表的链式存储构造实现十项根本操作:初始化要求终端输入数据建立链表,可用正序或逆序中的一种生成、求长度、取元素、求前导、求后继、查找、插入、删除、判定空表、置空,生成Llist.h 文件;编写 main 函数调用。【提示】 Llist.h 文件的代码实现线性表的链式存储构造的根本操作;另建一个链表.cpp 文件实现 main 函数,以用户交互的方式调用顺序表的各个功能。#include #in

8、clude L=NULL;#include int i;const MAXSIZE=100;for(i=n-1;i=0;-i)typedef int datatype;typedef struct Lnodelinklist s;s=new Lnode;datatype data;s-data=ai;struct Lnode *next;s-next=L;Lnode,*linklist;L=s;void CreateLink_L(linklist&L,datatypea,int n)专业资料整理WORD格式数据构造专业资料整理WORD格式电子商务06-3吴锋刚void PrintLink(li

9、nklist L)p=p-next;linklist p;printf(not find ! n);p=L;return NULL;int n=0;while(p)linklistLocateElemByIndex_L(linklistL,intn)coutdatanext;linklist p;n+;p=L;int i;coutnum of list elem is :nendl;for(i=0;inext;return k;linklist LocateElem_L(linklist L,datatype e)linklist p;p=L;while(p)if(p-data=e)print

10、f(find ! n);return p;p=p-next;/couti vlaue is :idata);return p;elseprintf(not find ! n);return NULL;void InsertList_L(linklist &L,int i,datatype e)linklist s,p,q;s=new Lnode;s-data=e;s-next=NULL;p=LocateElemByIndex_L(L,i);if(p=L)专业资料整理WORD格式数据构造专业资料整理WORD格式电子商务06-3吴锋刚s-next=L;#includeL=s;#inlucdelinklist.hvoid main()elselinklist L;q=L;linklist q;while(q-next!=p)datatype e;datatype aMAXSIZE;q=q-next;int i,n;char ch;q-next=s;coutinput num of elem:next=p;cinn;for(i=0;ie;&e)ai=e;linklist p,q;CreateLink_L(L,a,n);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 习题/试题

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号