#include<bits/stdc++.h>
using namespace std;
typedef struct node
{
int data;
struct node *before,*next;
}LNode,*LinkList;
LinkList CreatList(int n)
{
LNode *head,*tail,*p;
head=new LNode;
head->next=NULL;
head->before=NULL;
tail=head;
for(int i=1;i<=n;i++)
{
p=new LNode ;
cin>>p->data;
p->next=NULL;
p->before=NULL;
tail->next=p;
p->before=tail;
tail=p;
}
return head;
}
void SearchLNode(LinkList head,int m)
{
LNode *p;
int key;
for(int i=1;i<=m;i++)
{
cin>>key;
p=head->next;
while(p)
{
if(p->data==key)
{
if(p->next==NULL)
{
cout<<p->before->data<<endl;
break;
}
else if(p==head->next)
{
cout<<p->next->data<<endl;
}
else
{
cout<<p->before->data<<" "<<p->next->data<<endl;
break;
}
}
p=p->next;
}
}
}
int main ()
{
int n,m;
cin>>n>>m;
LinkList head;
head=CreatList(n);
SearchLNode(head,m);
return 0;
}
/***************************************************
User name: TJRAC6015203228魏杰
Result: Accepted
Take time: 0ms
Take Memory: 160KB
Submit time: 2016-11-02 12:27:05
****************************************************/
sdut2054数据结构实验之链表九:双向链表
最新推荐文章于 2020-01-14 15:24:12 发布