Given a singly linked list: A0→A1→…→An-1→An,
reorder it to: A0→An→A1→An-1→A2→An-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.
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.
Reorder it as explained above.
1 2 3
1 7 3 4
1 3 2
1 4 7 3
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.