题目:Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you must output 3→2→1→6→5→4; if K=4, 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 N (≤105) which is the total number of nodes, and a positive K (≤N) 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 N lines follow, each describes a node in the format:
Address Data Next
where Address is the position of the node, Data is an integer, and Next is the position of

给定一个单链表L和整数K,需要每隔K个节点反转链表。例如,对于链表1→2→3→4→5→6,如果K=3,输出3→2→1→6→5→4;如果K=4,则输出4→3→2→1→5→6。输入包含链表的首节点、节点总数N和反转长度K。程序需要处理包含孤立节点的情况,即不参与链表反转的节点。解决方案包括将链表数据存储到数组,整理并输出翻转后的链表。


被折叠的 条评论
为什么被折叠?



