Given a sorted singly linked list and a data, your task is to insert the data in the linked list in a sorted way i.e. order of the list doesn't change.
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.
For each test, the output will be space-separated integers denoting the values of the linked list.
The task is to complete the function sortedInsert() which should insert the element in sorted Linked List.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
1 <= T <= 100
1 <= N <= 104
-99999 <= A[i] <= 99999, for each valid i
25 36 47 58 69 80
19 25 36 47 58 69 80
50 75 100
Testcase 1: After inserting 19 at particular place, the linked list is like 19, 25, 36, 47, 58, 69, 80.
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.