欢迎来到天天文库
浏览记录
ID:9946882
大小:39.50 KB
页数:6页
时间:2018-05-16
《双向循环链表的实现》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、数据结构课程设计双向循环链表的实现设计要求:(1)定义教材P35所示“线性表的双向循环链表存储结构”,在此存储结构的基础上,实现如下操作。(2)建立带头结点的双向循环链表L。(3)在L中第i个位置之前插入新的元素e,如教材P36所示。(4)在L中删除第i个元素,并用e返回其值,如教材P37所示。(5)将L逆置。所选教材为严蔚敏的数据结构。//CreateList_L.cpp//TocreateaLinkList#include#include#include2、nio.h>#defineTRUE1#defineFALSE0#defineOK1#defineERROR0#defineINFEASIBLE-1#defineOVERFLOW-2typedefstructDuLNode{intdata;structDuLNode*prior;structDuLNode*next;}DuLNode,*DuLinkList;//初始条件:L已存在。操作结果:返回L中数据元素个数intListLength(DuLinkListL){inti=0;DuLinkListp=L->n3、ext;//p指向第一个结点while(p!=L)//p没到表头{i++;p=p->next;}returni;}//由双链循环线性表L的头结点出发,正序输出每个数据元素voidListTraverse(DuLinkListL){DuLinkListp=L->next;while(p!=L){cout<data<<"t";p=p->next;}cout<4、nkListp=L->prior;while(p!=L){cout<data<<"t";p=p->prior;}cout<next=L->prior=L;cout<<"CreateList_L"<5、======="<";cin>>n;cout<<"PleaseinputthedataforDuLinkListNodes:"<0;--i){p=(DuLinkList)malloc(sizeof(DuLNode));cin>>p->data;//ReverseorderinputingforCreatingaLinkList6、p->prior=L;p->next=L->next;L->next->prior=p;L->next=p;}if(n){cout<7、s;intj=0;inti;inte;cout<<"======"<<"beforeinsert:"<<"======"<>i;while(i<18、9、i>ListLength(L)+1){//i值不合法cout<<"illeaglelocation,pleaseinputthecorrectlocation:";cin>>i;}cout<<"inputthenumberyou10、wanttoinsert:";cin>>e;while(jnext;++j;}if(!(s=(DuLinkList)malloc(sizeof(DuLNode)))){cout<data=e;s->prior=p->prior;s->next=p;if(i==1)L->next=s;p->prior
2、nio.h>#defineTRUE1#defineFALSE0#defineOK1#defineERROR0#defineINFEASIBLE-1#defineOVERFLOW-2typedefstructDuLNode{intdata;structDuLNode*prior;structDuLNode*next;}DuLNode,*DuLinkList;//初始条件:L已存在。操作结果:返回L中数据元素个数intListLength(DuLinkListL){inti=0;DuLinkListp=L->n
3、ext;//p指向第一个结点while(p!=L)//p没到表头{i++;p=p->next;}returni;}//由双链循环线性表L的头结点出发,正序输出每个数据元素voidListTraverse(DuLinkListL){DuLinkListp=L->next;while(p!=L){cout<data<<"t";p=p->next;}cout<4、nkListp=L->prior;while(p!=L){cout<data<<"t";p=p->prior;}cout<next=L->prior=L;cout<<"CreateList_L"<5、======="<";cin>>n;cout<<"PleaseinputthedataforDuLinkListNodes:"<0;--i){p=(DuLinkList)malloc(sizeof(DuLNode));cin>>p->data;//ReverseorderinputingforCreatingaLinkList6、p->prior=L;p->next=L->next;L->next->prior=p;L->next=p;}if(n){cout<7、s;intj=0;inti;inte;cout<<"======"<<"beforeinsert:"<<"======"<>i;while(i<18、9、i>ListLength(L)+1){//i值不合法cout<<"illeaglelocation,pleaseinputthecorrectlocation:";cin>>i;}cout<<"inputthenumberyou10、wanttoinsert:";cin>>e;while(jnext;++j;}if(!(s=(DuLinkList)malloc(sizeof(DuLNode)))){cout<data=e;s->prior=p->prior;s->next=p;if(i==1)L->next=s;p->prior
4、nkListp=L->prior;while(p!=L){cout<data<<"t";p=p->prior;}cout<next=L->prior=L;cout<<"CreateList_L"<5、======="<";cin>>n;cout<<"PleaseinputthedataforDuLinkListNodes:"<0;--i){p=(DuLinkList)malloc(sizeof(DuLNode));cin>>p->data;//ReverseorderinputingforCreatingaLinkList6、p->prior=L;p->next=L->next;L->next->prior=p;L->next=p;}if(n){cout<7、s;intj=0;inti;inte;cout<<"======"<<"beforeinsert:"<<"======"<>i;while(i<18、9、i>ListLength(L)+1){//i值不合法cout<<"illeaglelocation,pleaseinputthecorrectlocation:";cin>>i;}cout<<"inputthenumberyou10、wanttoinsert:";cin>>e;while(jnext;++j;}if(!(s=(DuLinkList)malloc(sizeof(DuLNode)))){cout<data=e;s->prior=p->prior;s->next=p;if(i==1)L->next=s;p->prior
5、======="<";cin>>n;cout<<"PleaseinputthedataforDuLinkListNodes:"<0;--i){p=(DuLinkList)malloc(sizeof(DuLNode));cin>>p->data;//ReverseorderinputingforCreatingaLinkList
6、p->prior=L;p->next=L->next;L->next->prior=p;L->next=p;}if(n){cout<7、s;intj=0;inti;inte;cout<<"======"<<"beforeinsert:"<<"======"<>i;while(i<18、9、i>ListLength(L)+1){//i值不合法cout<<"illeaglelocation,pleaseinputthecorrectlocation:";cin>>i;}cout<<"inputthenumberyou10、wanttoinsert:";cin>>e;while(jnext;++j;}if(!(s=(DuLinkList)malloc(sizeof(DuLNode)))){cout<data=e;s->prior=p->prior;s->next=p;if(i==1)L->next=s;p->prior
7、s;intj=0;inti;inte;cout<<"======"<<"beforeinsert:"<<"======"<>i;while(i<1
8、
9、i>ListLength(L)+1){//i值不合法cout<<"illeaglelocation,pleaseinputthecorrectlocation:";cin>>i;}cout<<"inputthenumberyou
10、wanttoinsert:";cin>>e;while(jnext;++j;}if(!(s=(DuLinkList)malloc(sizeof(DuLNode)))){cout<data=e;s->prior=p->prior;s->next=p;if(i==1)L->next=s;p->prior
此文档下载收益归作者所有