Geeksforgeeks

Error

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.

**Example 1:**

**Input:
**LinkedList = 1->2->4
(the first and last node is connected,
i.e. 4 --> 1)
data = 2
**Output: **1 2 2 4**
**

**Example 2:**

**Input:
**LinkedList = 1->4->7->9
(the first and last node is connected,
i.e. 9 --> 1)
data = 5
**Output: **1 4 5 7 9

**Your Task:**

The task is to complete the function **sortedInsert**() which should insert the new node into the given circular linked list and return the head of the linkedlist.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(1)

**Constraints:**

0 <= N <= 10^{5}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Sorted insert for circular linked list

...