Given a linked list, reverse alternate nodes and append at the end
Submissions: 5253   Accuracy:

37.38%

  Difficulty: Medium   Marks: 4

Given a linked list, you have to perform the following task:

  1. Extract the alternative nodes from starting from second node.
  2. Reverse the extracted list.
  3. Append the extracted list at the end of the original list.

Input:
First line of input contains number of testcases T. For each testcase, first line of input contains number of testcases T. For each testcase, first line of input contains length of the linked list and next line contains the elements of the linked list.

Output:
The task is to modify the linked list as required.

User Task:
The task is to complete the function rearrange() which should rearrange the list as required.

Constraints:
1 <= N <= 50
1 <= Node_value <= 1000

Input:
1
8
10 4 9 1 3 5 9 4
5
1 2 3 4 5

Output:
10 9 3 9 4 5 1 4
1 3 5 4 2 

Explanation:
Testcase 1:
Reversing the alternative nodes from the given list, and then appending them to the end of the list results in a list with the elements as 10 9 3 9 4 5 1 4.

 

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

Author: Jaspreet Singh


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.



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


to report an issue on this page.