I donot understand the line— c=a;
c->next=merge(a->next,b);
Explain how c is getting connected to a or b.
Explain connection
@garganshul151
hello anshul,
when we do c=a; then address contained in pointer a is assigned to c;
and then in next line when we do c->next=merge(a->next,b) then pointer return by merge function is assigned to c->next.
and then at last we return c .
then using c pointer we iterate the whole resultant list.
pls dry run on ur own it will improve ur understanding
while doing dry run i dont able to understand what is assigning to c->next while calling
@garganshul151 let say we have TWO LISTS
2->NULL
3->NULL
we compare 2 and 3 ,2 is smaller so in c node with value 2 will be assigned
2 ©
c->next =merge( 2->next, 3->NULL)
which is basicallyy
2->next=merge( NULL, 3->NULL)
and now because one of the list is NULL we return head of another list which is 3 in our case
2->next=3->NULL
which can also be written as
2->3->NULL
pls refer this -> https://codevillage.wordpress.com/2016/09/03/merge-two-sorted-lists/
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.