class Solution {
public Node insert(Node head, int insertVal) {
Node root = new Node(insertVal);
if(head == null){
root.next = root;
return root;
}
if(head.next == head){
root.next = head;
head.next = root;
return head;
}
Node temp = head;
boolean flag = true;
int count = head.val;
while(temp != null){
if(temp.val != count){
flag = false;
}
if(temp.val <= insertVal && temp.next.val > insertVal){
root.next = temp.next;
temp.next = root;
return head;
}
temp = temp.next;
if(temp == head){
break;
}
}
while(temp != null){
if(temp.val > temp.next.val ){
root.next = temp.next;
temp.next = root;
break;
}
temp = temp.next;