Linklist merge sort wrong

https://ide.codingblocks.com/s/56890 all functionality of program is fine but it giving wrong output please kindly debug tell me what did i wrong in my code

@sanjeetboora kindly resolve my code.

Hey Neeraj, there are some small mistakes in your code

  • you are supposed to print output for each test case in new line so update your main() like this
    `print(head); cout<<endl;

  • your code will not work if both the linked list have equal number, so update your code’s line:46 as
    if(a->data<=b->data)
    `

  • Your code will not work if there is a negative number in the linked list, for eg. check for this case
    input:
    1
    2
    1 1
    2
    -1 2
    your code’s output :
    1 1 2
    but the expected output is:
    -1 1 1 2

https://ide.codingblocks.com/s/56890 please kindly debug it again giving wrong output

@sanjeetboora please debug the code

@sanjeetboora please help me

Hey Neeraj, you still haven’t fixed your code for the above mentioned input. To correct your code update code’s line:68 like this head = merge(head,head2); because here you have to update your head with the node returned from merge().

@sanjeetboora thank you so much