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

链表单链表双向循环试验报告讲解VIP免费

链表单链表双向循环试验报告讲解_第1页
1/17
链表单链表双向循环试验报告讲解_第2页
2/17
链表单链表双向循环试验报告讲解_第3页
3/17
数据结构实验报告T1223-3-21余帅实验一实验题目:仅仅做链表部分难度从上到下1.双向链表,带表头,线性表常规操作。2.循环表,带表头,线性表常规操作。3.单链表,带表头,线性表常规操作。实验目的:了解和掌握线性表的逻辑结构和链式存储结构,掌握单链表的基本算法及相关的时间性能分析。实验要求:常规操作至少有:1.数据输入或建立2.遍历3.插入4.删除必须能多次反复运行实验主要步骤:1、分析、理解给出的示例程序。2、调试程序,并设计输入数据,测试程序的如下功能:1.数据输入或建立2.遍历3.插入4.删除单链表示意图:datadatadatadatadatadatadatadataNULLheaddatadatadatadatadatadatadatadataheaddatadatadatadataputdatadatadataheadNULLNULL创建删除添加双向循环链表示意图:程序代码://单链表#include删除pre┆┊nextpredatanextpredatanextpredatanextpredatanextheadheadpre┆┊nextpredatanextpredatanextpredatanextpredatanext创建#includeconstMAX=5;enumreturninfo{success,fail,overflow,underflow,range_error};intdefaultdata[MAX]={11,22,33,44,55};classnode{public:intdata;node*next;};classlinklist{private:node*headp;protected:intcount;public:linklist();~linklist();boolempty();voidclearlist();returninfocreate(void);returninfoinsert(intposition,constint&item);returninforemove(intposition);returninfotraverse(void);};linklist::linklist(){headp=newnode;headp->next=NULL;count=0;}linklist::~linklist(){clearlist();deleteheadp;}boollinklist::empty(){if(headp->next==NULL)returntrue;elsereturnfalse;}voidlinklist::clearlist(){node*searchp=headp->next,*followp=headp;while(searchp->next!=NULL){followp=searchp;searchp=searchp->next;deletefollowp;}headp->next=NULL;count=0;}returninfolinklist::create(){node*searchp=headp,*newnodep;for(inti=0;idata=defaultdata[i];newnodep->next=NULL;searchp->next=newnodep;searchp=searchp->next;count++;}searchp->next=NULL;traverse();returnsuccess;}returninfolinklist::insert(intposition,constint&item)//插入一个结点{if(position<=0||position>=count)returnrange_error;node*newnodep=newnode,*searchp=headp->next,*followp=headp;for(inti=1;inext;}newnodep->data=item;//给数据赋值newnodep->next=followp->next;//注意此处的次序相关性followp->next=newnodep;count++;//计数器加一returnsuccess;}returninfolinklist::remove(intposition)//删除一个结点{if(empty())returnunderflow;if(position<=0||position>=count+1)returnrange_error;node*searchp=headp->next,*followp=headp;//这里两个指针的初始值设计一前一后for(inti=1;inext;}followp->next=searchp->next;//删除结点的实际语句deletesearchp;//释放该结点count--;//计数器减一returnsuccess;}returninfolinklist::traverse(void){node*searchp;if(empty())returnunderflow;searchp=headp->next;cout<<"连表中的数据为:"<data<<"";searchp=searchp->next;}cout<

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

碎片内容

链表单链表双向循环试验报告讲解

确认删除?
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群