Insert in a Sorted List
Submissions: 12198   Accuracy:

43.83%

  Difficulty: Easy   Marks: 2

Given a sorted singly linked list and a data, your task is to complete the function sortedInsert() that inserts the data in the linked list in sorted way i.e. order of the list doesn't changes.

Input:
The function takes 2 arguments as input, reference pointer to the head of the sorted single linked list and an integer data value which is to be inserted in the list.
There are multiple test cases and for each test case the function will be called separately.

Output:
For each test output will be space separated integers denoting the values of the linked list.

User Task:
The task is to complete the function sortedInsert() which should insert the element in sorted Linked List.

Constraints:
1 <= T <= 100
0 <= N <= 100
-999 <= A[] <= 999

Example:
Input:

2
6
25 36 47 58 69 80
19
2
50 100
75

Output:
19 25 36 47 58 69 80
50 75 100

Explanation:
Testcase 1
: After inserting 19 at particular place, the linked list is like 19, 25, 36, 47, 58, 69, 80.

 

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

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.