//双向链表,查找 key 的前驱和后继
#include "iostream"
using namespace std;
struct node
{
int data;
struct node *before, *next;
};
int main()
{
int n, key;
cin >> n >> key; //n个数,要查找的数 key
struct node *tail, *head, *p;
head = (struct node *)malloc(sizeof(struct node));
head->next = NULL;
head->before = NULL;
tail = head;
//建立双向链表
for (int i = 1; i <= n; i++)
{
p = (struct node *)malloc(sizeof(struct node));
cin >> p->data;
p->next = NULL;
p->before = NULL;
tail->next = p;
p->before = tail;
tail = p;
}
//找到 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;
break;
}
else
{
cout << p->before->data << " " << p->next->data << endl;
break;
}
}
p = p->next;
}
return 0;
}