SDUTOJ 2054 双向链表-LMLPHP

#include<iostream>
#include<stdlib.h>
using namespace std;
typedef int ElemType;
typedef struct LNode
{
ElemType data;
struct LNode *next1,*next2;
}*LinkList;
int main()
{
int n,m,i,t;
cin>>n>>m;
LinkList L,p,tail;
L=new LNode;
L->next1=NULL;
tail=L;
for(i=0;i<n;i++)
{
p=new LNode;
cin>>p->data;
p->next1=NULL;
p->next2=NULL;
tail->next1=p;
p->next2=tail;
tail=p;
}
tail=L->next1;
while(m--)
{
cin>>t;
for(i=0;i<n;i++)
{
if(tail->data==t)
{
if(tail->next2!=L)
cout<<tail->next2->data<<" ";
if(tail->next1!=NULL)
cout<<tail->next1->data<<endl;
else
cout<<"\n";
}
tail=tail->next1;
}
tail=L->next1;
}
return 0;
}

05-02 01:12