Linked list mergesort not sorting negative numbers


here is my code my code is not sorting negative or mixture of negative and positive number

What is wrong with this it is not passing all test cases

Hey @sheikhhaji18

int main(){
    LinkList l;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int data;
        cin>>data;
        l.Insertion_at_tail(data);
    }
    node* head=l.head;
    l.head= MergeSort(head); //updated this line 
    l.print();
}

But why this was working fine for positive number? just to know what i did wrong

No it wont
In that case which u tried original head and new list head may be the smallest element

After merge sort ur class object head was same as that of before that’s why it wasn’t working :slight_smile: