99 views
How to trace the below program?

p and q are the starting address of two different linked list

struct node*Do(struct node*p,struct node*q){
struct node*ps,*qs;
if(!p){
return(q);
}
else if(!q){
return(p);
}
else{
return(p);
}
}
| 99 views

If list 1 is a-->b-->c and list 2 is d-->e then output will be a-->d-->b-->e-->c

Procedure:

by Loyal (5.6k points)
edited

take 2 different list with same length and blindly apply the code
1) a-b-c-d
2) g-h-i-j

take 2 different list with lengths are not same and blindly apply the code
1) a-b-c-d-e-f
2) g-h-i-j

take 2 different list with lengths are not same and blindly apply the code
1) a-b-c-d
2) g-h-i-j-k-l

Answer:: They are merging those lists, where stats with p, take a node from p list and take a node from q list and repeat until one of list completed, after that remaining list is keep it as it is

a-g-b-h-c-i-d-j-e-f is the o/p for the i/p

1) a-b-c-d-e-f
2) g-h-i-j
by Veteran (64.7k points)
0
I want to know that how the function calls push and pop in the stack for the above recursion.

can you give me the stack diagram of the function calls?
0

Shaik Masthan  can you please check the output once more because i am getting something different

0

May be i mistaken... but i didn't found it,i still getting my answer is true, Please post your output, i will compare

0

this is what i am getting

0
i am not getting your solution...

is it a-d-b-e-c ?
0
NO, can you post you solution please
+1
i hope you mistakenly forget that, p is a local variable
+1
sorry ,  Shaik Masthan sir you are right. Now i got it