Doubly linked list Time limit:1000ms Memory limit:65536k have questions? Dot here ^_^ Title Description
Learned the one-way list, we have a problem-solving ability, single-linked list with a pointer to the memory to find the next position, which is not easy to break the chain. But a single-linked list has a weakness-it can't be referred to. For example, there are two nodes in the list, A, B, their relationship is a successor of a, a pointing to B, can easily be found by a B, but from B can not find a. A simple idea can easily solve this problem-set up a doubly linked list. In a doubly linked list, A has a pointer pointing to Node B, and B has a pointer to a. This will not only traverse the entire list of nodes from the node of the list head, but also traverse all nodes from the end of the linked list node. For a given column of data, in the given order to establish a doubly linked list, according to the keyword to find the corresponding node, output this node's predecessor node keyword and the successor node key word.
Input
The first line is two positive integers n (representing the number of nodes), m (the number of keywords to find). The next n rows have an integer in each row as the keyword key (the data guarantees that the keyword is not duplicated in the sequence). Next there are M keywords, each of which takes one line.
Output
For each keyword given, output this keyword precursor keyword and the successor node keyword. If the given keyword does not have a precursor or successor, it is not output. The given keyword takes one row for each output.
Sample input
10 31 2 3 4 5 6 7 8 9 0350
Sample output
2 44 69
Hint code: In the game code temporarily paste not come out!
Sdut OJ 2054 bidirectional linked list implementation (struct node pointer + traversal * "template")