BETA

Difficulty Level: Hard

Submissions: 4615 Accuracy:

36.08%

Reorder List (Function Problem)
     

Given a singly linked list: A0A1→…→An-1An,
reorder it to: A0AnA1An-1A2An-2→…

Given 1->2->3->4->5 its reorder is 1->5->2->4->3.

It is recommended do this in-place without altering the nodes' values.

Input:

In this problem, method takes one argument: Address of the head of the linked list. The function should not read any input from stdin/console.
The node structure has a data part which stores the data and a next pointer which points to the next element of the linked list. 
There are multiple test cases. For each test case, this method will be called individually.

Output:

Reorder it as explained above.

Constraints:

1<=T<=200
1<=N<=200

Example:

Input:

2
3
1 2 3
4
1 7 3 4

Output:

1 3 2
1 4 7 3

 

 

 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Amit Khandelwal


					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.