BETA

Difficulty Level: Basic

Submissions: 2999 Accuracy:

34.91%

Insert a node in Doubly linked list (Function Problem)
     

Given a doubly linked list, a position p and an integer x your task  is to add a new node with value x at position just after pth node in the doubly linked list .
In this function problem, the function addNode() takes three argument: Address of the head of the linked list,  the position p and integer x  where the node is to be added . 
There are multiple test cases. For each test case, this function will be called individually.

Note: The first node is considered as node no 0.

Example

Input:
The first line contains an integer 'T' denoting the number of test cases. Then 'T' test cases follow. Each test case consists of 3 lines. First line of each test case contains an integer N denoting the size of the linked list. Second line of each test case consists of 'N' space separated integers denoting the elements of the linked list.The third line contains two integers p and x

 

Output:
Prints the nodes of the linked list .

Constraints:
1<=T<=200
1<=N<=200

Example:
Input:
2
3
2 4 5
2 6
4
1 2 3 4
0 44

Output:
2 4 5 6
1 44 2 3 4


Note:  The Input/Ouput format and Example given below is used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console, and should not print anything on st stdout/console.

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

Contributor: Amit Khandelwal, Harshit Sidhwa


					   
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.