Insert in a Sorted List
Submissions: 10322   Accuracy:

40.68%

  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.

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

Note:The Input/Ouput format and Example given are 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. The task is to complete the function specified, and not to write the full code.

** 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.