# 数据结构-双向链表插入

 #include<iostream>
#include<stdlib.h>
using namespace std;

typedef struct Dulnode
{
int data;
struct Dulnode *prior,*next;
}DulNode;

DulNode *Input(int n)
{

for(int i=0;i<n;i++)
{
int data;
cin>>data;
q=(DulNode*)malloc(sizeof(DulNode));
q->data=data;
q->next=p->next;
q->prior=p;
p->next=q;
p=q;
}
}

void ShowPos(DulNode *L)
{
DulNode *p;
p=L->next;
while(p!=L)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}

int InsertPos(DulNode *L,int id,int num)
{
DulNode *p,*s;
p=L;
int mark=1;
int pos=0;
while(p!=L||mark)
{
if(pos==id-1)
{
s=(DulNode*)malloc(sizeof(DulNode));
s->data=num;
s->next=p->next;
p->next->prior=s;
p->next=s;
s->prior=p;
return 1;
}
p=p->next;
pos++;
mark=0;
}
if(pos!=id) return 0;
}

int main()
{
int n;
while(cin>>n)
{
cout<<"正向遍历:";
while(1)
{
int id,num;
cout<<"输入插入的序号:";
cin>>id;
cout<<"输入插入的数据:";
cin>>num;
{
cout<<"正向序号:";
//cout<<"逆向序号:";
}
else cout<<"序号无效"<<endl;
}
}
return 0;
} 

 #include<iostream>
#include<stdlib.h>
using namespace std;

typedef struct Dulnode
{
int data;
struct Dulnode *prior,*next;
}DulNode;

DulNode *Input(int n)
{

for(int i=0;i<n;i++)
{
int data;
cin>>data;
q=(DulNode*)malloc(sizeof(DulNode));
q->data=data;
q->next=p->next;
q->prior=p;
p->next=q;
p=q;
}
}

void ShowNeg(DulNode *L)
{
DulNode *p;
p=L->prior;
while(p!=L)
{
cout<<p->data<<" ";
p=p->prior;
}
cout<<endl;
}

void ShowPos(DulNode *L)
{
DulNode *p;
p=L->next;
while(p!=L)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}

int InsertNeg(DulNode *L,int id,int num)
{
DulNode *p,*s;
p=L;
int mark=1;
int pos=0;
while(p!=L||mark)
{
if(pos==id-1)
{
s=(DulNode*)malloc(sizeof(DulNode));
s->data=num;
s->next=p->next;
p->next->prior=s;
p->next=s;
s->prior=p;
return 1;
}
p=p->prior;
pos++;
mark=0;
}
if(pos!=id) return 0;
}

int main()
{
int n;
while(cin>>n)
{
cout<<"逆向遍历:";
while(1)
{
int id,num;
cout<<"输入插入的序号:";
cin>>id;
cout<<"输入插入的数据:";
cin>>num;
{
cout<<"逆向序号:";
}
else cout<<"序号无效"<<endl;
}
}
return 0;
} 

11-04 849

11-30 3585
03-21 152
04-23 1750
08-12 2923
05-06 2万+
02-01 4331
10-08 448
03-15 309
09-27 208
08-22 3081
03-27 3006
03-08 490
07-27 2万+
12-10 1万+
07-19 875
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie