- 1、本文档共6页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
双向循环链表的实现精选
数据结构课程设计
双向循环链表的实现
设计要求:
(1)定义教材P35所示“线性表的双向循环链表存储结构”,在此存储结构的基础上,实现如下操作。
(2)建立带头结点的双向循环链表L。
(3)在L中第i个位置之前插入新的元素e,如教材P36所示。
(4)在L中删除第i个元素,并用e返回其值,如教材P37所示。
(5)将L逆置。
所选教材为严蔚敏的数据结构。
//CreateList_L.cpp
//To create a LinkList
#include stdlib.h
#include iostream.h
#include conio.h
# define TRUE 1
# define FALSE 0
# define OK 1
# define ERROR 0
# define INFEASIBLE -1
# define OVERFLOW -2
typedef struct DuLNode
{ int data;
struct DuLNode *prior;
struct DuLNode *next;
}DuLNode,*DuLinkList;
// 初始条件:L已存在。操作结果:返回L中数据元素个数
int ListLength(DuLinkList L)
{
int i=0;
DuLinkList p=L-next; // p指向第一个结点
while(p!=L) // p没到表头
{
i++;
p=p-next;
}
return i;
}
// 由双链循环线性表L的头结点出发,正序输出每个数据元素
void ListTraverse(DuLinkList L)
{
DuLinkList p=L-next;
while(p!=L)
{
coutp-data\t;
p=p-next;
}
coutendl;
}
// 由双链循环线性表L的头结点出发,逆序输出每个数据元素
void ListTraverseBack(DuLinkList L)
{
DuLinkList p=L-prior;
while(p!=L)
{
coutp-data\t;
p=p-prior;
}
coutendl;
}
//To Creatre a DuLinkList L with HeadNode
void CreateList_DuL(DuLinkList L)
{
int n;
int i;
DuLNode *p;
L=(DuLinkList)malloc(sizeof(DuLNode));
L-next=L-prior=L;
coutCreateList_Lendl================endl;
coutPlease input the Init DuLinkNode Number: eg. 5 ;
cinn;
coutPlease input the data for DuLinkList Nodes: eg. 34,67,3,-9,45,...endl;
for(i=n;i0;--i)
{
p=(DuLinkList)malloc(sizeof(DuLNode));
cinp-data; //Reverse order inputing for Creating a LinkList
p-prior=L;
p-next=L-next;
L-next-prior=p;
L-next=p;
}
if(n)
{
coutendl;
coutSuccess to Create a DuLinkList !endl;
ListTraverse(L);
coutendl;
}
else coutA NULL DuLinkList have been created !endl;
}
//ListInsert_Dul()
int ListInsert_DuL(DuLinkList L)
{
DuLNode *p=L,*s;
int j=0;
int i;
int e;
cout======before insert:======endl;
ListTraverse(L);
coutinput the location you want to inse
文档评论(0)