Sorted insert for circular linked list
Submissions: 19080   Accuracy:

26.7%

  Difficulty: Easy   Marks: 2

Given a sorted circular linked list, the task is to insert a new node in this circular list so that it remains a sorted circular linked list.

Input:
First line of input contains number of testcases T. For each testcase first line of input contains length of the linked list, next line contains the linked list elements and the last line contains the element to be inserted into the linked list.

Output:
For each testcase, print the new linked list.

User Task:
The task is to complete the function sortedInsert() which should insert the new node into the given circular linked list.

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

Example:
Input:
2
3
1 2 4
2
4
1 4 7 9
5

Output:
1 2 2 4
1 4 5 7 9

Explanation:
Testcase 2:
After inserting 5, the linked list would be 1, 4, 5, 7 and 9.

 

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

Author: bhawnamait


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.