https://ide.geeksforgeeks.org/ocvIhWZI9s-----what’s error in my code
Merger Sorted Linked List Probem
it is showing inlavid index and please at once try an input of ur choice and see if there are another errors and help me to correct them
@AbhishekAhlawat1102
you have to use else if in the mergefunction.
public void merge_sorted_list(LinkedList other) throws Exception {
LinkedList l = new LinkedList();
int i = 0,j=0;
while(i<this.size&&j<other.size){
if(this.getAt(i)<=other.getAt(j)){
l.addLast(this.getAt(i));
i++;
}
else if(this.getAt(i)>other.getAt(j)){
l.addLast(other.getAt(j));
j++;
}
}
if(i == this.size){
while(j<other.size){
l.addLast(other.getAt(j));
j++;
}
}
if(j == other.size){
while(i<this.size){
l.addLast(this.getAt(i));
i++;
}
}
l.display();
}