Segmentation Fault Merge Sorted List


Can you please tell why it is showing segmentation fault?

se even for input like
1
4
1 2 3 4
0
you get wrong answer.The Approach is pretty simple that we will Start from the head of the two lists and consume that element from the two of the Lists first which is smaller and add that element into the ans list. After consuming, Advance the iterator to point to the next node in the list. The size of the Lists can be different so after consuming elements simultaneously from the two list, We need to check if any of the two list is empty, and add the elements of that list as it is in the answer List.
simple as this https://ide.codingblocks.com/s/465399