#include<stdio.h>
typedef struct DuLNode
{
int data;
struct DuLNode *prior;
struct DuLNode *next;
}DuLNode,* DuLinkList;
void ListInsert(DuLinkList &L,DuLNode *p,DuLNode *s)
{
s->prior=p->prior;
p->prior->next=s;
s->next=p;
p->prior=s;
}
int main()
{
int m,n,i;
scanf("%d",&m);
DuLinkList p=new DuLNode;
DuLinkList L=p;
for(i=0;i<m;i++)
{
DuLinkList s=new DuLNode;
s->data=i;
s->prior=p;
p->next=s;
p=s;
p->next=L;
L->prior=p;
}
DuLinkList x=L;
scanf("%d",&n);
for(i=1;i<=n;i++)
x=x->next;
DuLinkList y=new DuLNode;
y->data=10;
ListInsert(L,x,y);
p=L->prior;
while(p!=L)
{
printf("%d ",p->data); //插入,逆着输出数
p=p->prior;
}
printf("\n");
p=L->next;
for(i=0;i<=m;i++)
{
printf("%d ",p->data); //插入,直接输出
p=p->next;
}
printf("\n");
return 0;
}
转载于:https://www.cnblogs.com/NYNU-ACM/p/4237352.html