using namespace std;
typedef struct DNode{
int data;
struct DNode* prior,*next;
}DNode,*DLinklist;
//建立双链表
void BuildDLinklist(DLinklist &L){
L =(DLinklist)malloc(sizeof(DNode));
L->next=NULL;
L->prior=NULL;
DNode *p = L;
int x;
cout<<"输入双链表的每一项,输入-1结束输入:";
cin>>x;
while (x!=-1) {
DNode *s = new DNode;
s->next = p->next;
s->prior = p;
p->next = s;
s->data = x;
p = s;
cin>>x;
}
}
//按序号查找
DNode *GetElmeById(DLinklist L,int i){
int j=1;
DNode *p = L->next;
if (i==0) {
return L;
}
if (i<1) {
return NULL;
}
while (p&&j<i) {
p=p->next;
j++;
}
return p;
}
//插入数据
void InsertDLinklist(DLinklist &L,int i,int x){
DNode *p = GetElmeByI
C++双链表简单操作
最新推荐文章于 2022-09-17 21:38:38 发布
本文介绍了C++中如何实现双链表的基本操作,包括插入、删除、遍历等,同时探讨了双链表在数据结构中的重要性和应用。
摘要由CSDN通过智能技术生成