#include <iostream>
using namespace std;
typedef struct DLNode{
int data;
DLNode *next,*prior;
}DLNode,*DuLink;
int main()
{
int n;
cin>>n;
DuLink L,t,p;
L->prior=NULL;
p=L;
while(n--)
{
t=new DLNode;
cin>>t->data;
p->next=t;
t->prior=p;
t->next=NULL;
p=t;
}
p=L->next;
while(p->next)
{
cout<<p->data<<' ';
p=p->next;
}
cout<<p->data<<endl;
while(p!=L)
{
cout<<p->data<<' ';
p=p->prior;
}
return 0;
}
(头歌)双向链表的创建和遍历
最新推荐文章于 2024-10-07 17:39:40 发布