01 | #include <iostream> |
02 | using namespace std; |
03 | class linklist { |
04 | private : |
05 | class linknode { |
06 | public : |
07 | int data; |
08 | linknode *pre, *next; |
09 | linknode():pre(NULL),next(NULL) {} |
10 | linknode( int d):data(d),pre(NULL),next(NULL) {} |
11 | }; |
12 | linknode *head, *tail; |
13 | public : |
14 | linklist() { |
15 | head= new linknode(); |
16 | tail=head; |
17 | } |
18 | void add( int data) { |
19 | linknode *temp= new linknode(data); |
20 | |
21 | tail->next=temp; |
22 | temp->pre=tail; |
23 | tail=temp; |
24 | } |
25 | void display( int x) { |
26 | linknode *p=head->next; |
27 | while (x!=p->data&&p) { |
28 | p=p->next; |
29 | } |
30 | if (p) { |
31 | if (p==head->next) cout<<p->next->data<<endl; |
32 | else if (p==tail) cout<<p->pre->data<<endl; |
33 | else |
34 | cout<<p->pre->data<< ' ' <<p->next->data<<endl; |
35 | } |
36 | } |
37 | }; |
38 | int main() { |
39 | int n, m; |
40 | cin>>n>>m; |
41 | linklist l; |
42 | while (n--) { |
43 | int x; |
44 | cin>>x; |
45 | l.add(x); |
46 | } |
47 | while (m--) { |
48 | int x; |
49 | cin>>x; |
50 | l.display(x); |
51 | } |
52 | return 0; |
53 | } |