#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef struct node
{
int data;
struct node *next, *last;
} Lnode;
Lnode *creat(int n)
{
int i;
Lnode *p, *tail, *head;
head = new Lnode;
head->next = NULL;
head->last = NULL;
tail = head;
for(i = 1; i <= n; i++)
{
p = new Lnode;
cin >> p->data;
p->last = tail;
p->next = NULL;
tail->next = p;
tail = p;
}
return head;
}
void LSearch(Lnode *head, int x)
{
Lnode *p;
p = head->next;
while(p->data != x)
p = p->next;
if(p->last->last == NULL)
cout << p->next->data << endl;
else if(p->next == NULL)
cout << p->last->data << endl;
else
cout << p->last->data << " " << p->next->data << endl;
}
int main()
{
Lnode *head;
int n, m, x;
cin >> n >> m;
head = creat(n);
while(m--)
{
cin >> x;
LSearch(head, x);
}
return 0;
}
/***************************************************
User name: Shawn
Result: Accepted
Take time: 0ms
Take Memory: 204KB
Submit time: 2017-07-27 11:15:00
****************************************************/
sdut 双向链表
最新推荐文章于 2020-06-06 15:04:36 发布