Reversing Linked List

Given a constant??and a singly linked list?, you are supposed to reverse the links of every??elements on?. For example, given?being 1→2→3→4→5→6, if?, then you must output 3→2→1→6→5→4; if?, you must output 4→3→2→1→5→6.

Input Specification:

Each input file contains one test case. For each case, the first line contains the address of the first node, a positive??() which is the total number of nodes, and a positive??() which is the length of the sublist to be reversed. The address of a node is a 5-digit nonnegative integer, and NULL is represented by -1.

Then??lines follow, each describes a node in the format:

where?Address?is the position of the node,?Data?is an integer, and?Next?is the position of the next node.

Output Specification:

For each case, output the resulting ordered linked list. Each node occupies a line, and is printed in the same format as in the input.

Sample Input:

Sample Output:

代码: