P823 Play with Linked List

Play with Linked List

题目描述

Given a singly linked list L​1→L​2→⋯→Ln−1 →Ln and an integer 1≤k<n, you are supposed to rearrange the links to obtain a list like L​k→Ln→Lk−1→Ln−1→⋯. For example, given L being 1→2→3→4→5→6 and k=4, you must output 4→6→3→5→2→1.

输入格式

Each input file contains one test case. For each case, the first line contains the address of the first node, a positive N (≤10^​5) which is the total number of nodes, and an integer 1≤k<n where n is the number of nodes in the linked list. The address of a node is a 5-digit nonnegative integer, and NULL is represented by -1.

🔒
登录后查看完整题面
登录后查看题目

统计