Merge using STS---

its giving me segmentation error

Hello @sid.rajput23 please explain your logic.

i made 2 list first
then
used a merge function which will return head of the linked list (c1) of type list::iterator
then for checking base case as iterator can’t point to NULL it wrote if(next(a)==prev(a))
i think due to this the segmentation fault was there because there is no next(a)/prev(a) exist for an empty list
then i commented it but still gor segmentation fault

@sid.rajput23 no you should add that base case because if either list a becomes empty first then you have to return b.
and if b becomes empty first then you have to return a then.

how to check through an iterator for list if its empty or not??
and why segmentation error is there?

segmentation error because you are not checking the base case:
and i am not sure about iterators in this question.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.