Merge Lists Alternatingly
Submissions: 5295   Accuracy:

37.1%

  Difficulty: Easy   Marks: 2

Given two linked lists, your task is to complete the function mergeList() which inserts nodes of second list into first list at alternate positions of first list.

Input:
First line of input contains number of testcases T. For each testcase there will be 4 lines. First line consists of the length of the first linked list, next line contains elements of the linked list. Third line contains length of another linked list and next line contains elements of the linked list.

Output:
For each test case first print space separated vales of the first linked list, then in the next line print space separated values of the second linked list.

User Task:
The task is to complete the function mergeList() which should merge the two lists as required.

Constraints:
1 <= T <= 100
1 <= N <= 100

Example:
Input:

2
2
9 10
6
5 4 3 2 1 6
5
99 88 77 66 55
5
55 44 33 22 11

Output:
10 6 9 1 2 3 4 5 
55 11 66 22 77 33 88 44 99 55

Explanation:
Testcase 1
: After merging the two lists as required, the new list is like: 10-> 6-> 9-> 1-> 2-> 3-> 4-> 5.

 

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

Contributor: Harshit Sidhwa
Author: harshitsidhwa


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.