Runtime error in each of the linked list code

https://ide.codingblocks.com/s/56751 (This is the sortedMerge code)
https://ide.codingblocks.com/s/56757 (This is the merge code)
https://ide.codingblocks.com/s/56759 (This is the cycle detect and break code)
https://ide.codingblocks.com/s/56785 (Append last k code)
I am getting runtime error in each of the code. I am not able to understand.

https://ide.codingblocks.com/s/56751 it is working fine

No Runtime Error or any other sorts of errors are occuring while running the above codes.
They are working perfectly fine and giving correct outputs.

In the first code I am getting a wrong answer whereas in the CB IDE it is giving correct ouput.

which compiler are you using?

the one that is in the course challenges

Well Hardik it’s working fine everywhere. If you have doubt in specific question then pls share the question link over here.

Hi Hardik, there are some errors in your code. First is that you’re calling the sortedMerge and printres loops outside the while loop for testcases. So, the functions will be called only once for all the test cases. So, you need to call the functions inside that while loop. Secondly, you need to print a new line after every test case’s output. Thirdly, since you’ve declared a and b outside the while loop for testcases, a and b will be initialised only for the first test case and will remain the same for subsequent test cases. So, to solve this, you can either return the root node from the insert function or you can simply declare a and b inside the while loop for testcases - in this case, a and b both will be reinitialised to NULL for every test case.

I’ve resolved these errors and you can refer to the updated code here: https://ide.codingblocks.com/s/64533