What is problem in my code

public void merge_sorted_list(linkedList other) {
Node temp=this.head;
Node temp1=other.head;
if(temp.data<temp1.data){
temp=temp.next;
}else{
Node temp2=temp.next;
temp.next=temp1;
temp1=temp1.next;
temp.next.next=temp2;

	}
   temp=this.head;
 
   while(temp.next!=null && temp1.next!=null) {
	   if(temp.next.data<temp1.data){
			temp=temp.next;
		}else{
			Node temp2=temp.next;
			temp.next=temp1;
			temp1=temp1.next;
			temp.next.next=temp2;
			temp=temp.next;
			
		}
	   if(temp.next==null && temp1.next!=null) {
		   temp.next=temp1;
		   while(temp1.next!=null) {
			   temp1=temp.next;
		   }
	   }
	   if(temp.next!=null && temp1==null) {
		   while(temp!=null) {
			   temp=temp.next;
		   }
	   }
	   
	  
   }
   if(temp.next.data<temp1.data){
		temp=temp.next;
	}else{
		Node temp2=temp.next;
		temp.next=temp1;
		temp1.next=temp2;
		
	}
   
    display();  

}

hi @sksumitkumardiwaker
there no need to do inplace merge sort . you can simply create new LinkedList and addLast each node which is smaller in the same way you do merge of two arrays.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.