#include<iostream.h>
struct dnode
{
int data;
dnode *next;
dnode *prior;
};
dnode *Creat_dnode_linklist(int n,int a[])//创建双向链表
{
int i;
dnode *head,*p;
p=new(dnode);
head=p;
head->prior=NULL;
head->next=NULL;
p->data=a[n-1];
p->prior=head;
p->next=head->next;
head->next=p;
for(i=n-2;i>=0;i--)
{
p=new(dnode);
p->data=a[i];
p->prior=head;
p->next=head->next;
head->next=p;
}
return p;
}
void Prior_Insert_dnode_linklist(int x,int a,dnode *h)//前插
{
dnode *s,*p;
p=h;
s=new(dnode);
s->data=x;
while(p->next->data!=a&&p->next)
p=p->next;
s->next=p;
s->prior=p->prior;
p->prior->next=s;
p->prior=s;
}
void display(dnode *h)//显示链表
{
dnode *p;
p=h;
while(p->next!=h)
{ cout<<p->data<<"->";
p=p->next;
}
cout<<p->data<<endl;
}
void main()
{
int a[10]={1,2,3,4,5,6,7,8,9,10};
dnode *h;
h=Creat_dnode_linklist(10,a);
//Prior_Insert_dnode_linklist(12,5,h);
display(h);
}