Sdut OJ 2054 bidirectional linked list implementation (struct node pointer + traversal * "template")

Source: Internet
Author: User
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")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.