1. You are given a sorted cyclic linked list N nodes.
2. In a cyclic linked list, the last node of the linked list is connected
to the head of the linked list.
3. You are also given a number X.
3. You have to write a function that inserts X into the list such
that it remains a sorted cyclic list.
Note:
1. If there are multiple suitable places for insertion, you may choose
any place to insert the new value. After the insertion, the cyclic
list should remain sorted.
2. If the list is empty (i.e., given node is null), you should create
a new single cyclic list and return the reference to that single
node. Otherwise, you should return the original given node.
4. display is a utility function which displays the contents of Linked List,
feel free to use it for debugging purposes.
5. main takes input from the users and creates the Linked List. You can use
display to know its contents.
6. This is a functional problem.
7. You should code only the insert function. It takes as input the
head of the linked list and X. It should return the head of modified list.
8. Don't change the code of Node, main and display.Input Format
First line takes N, the number of elements in the list. Second line takes input N space separated numbers reperesenting elements of the linked list. Third line takes input X. Input is handled for you.
Output Format
1 if insertion in list is correct, else 0. Output is handled for you.
Constraints
1 <= N <= 1000
Notice
Try First, Check Solution later
1. You should first read the question and watch the question video.2. Think of a solution approach, then try and submit the question on editor tab.3. We strongly advise you to watch the solution video for prescribed approach.Example
Input
6 1 2 3 3 4 5 5
Output
1