122 views

What does the following program do on two linked lists?

Struct node  *myFun (struct node  * a, struct node * b)

{

Struct node   *new = NULL ;

If (a = = NULL) return (b) ;

if (b = = NULL) return (a) ;

If (a → data <= b → data)

{

new = a ;

new → next = myFun (a → next, b) ;

return (new);

}

else

{

new = b ;

new → next = myFun (a, b → next) ;

return (new) ;

}

}



if options are

• merges two unsorted linked lists

• merges two linked lists by selecting the alternate nodes

• merges two linked lists by selecting the nodes in reverse.

in DS
edited | 122 views
+2
If the two lists are sorted then combining them into a sorted list

The Program is basically merging two linked list in such a way that the start of the merged list becomes the smaller start from the given list..

The output varies from case to case..

case 1-

first list-  1->2->3->4

second list - 5->6->7

output - 1->2->3->4->5->6->-7

case 2-

first list - 3->2

second list-1->4

output - 1->3->2->4

case 3-

first list- 4->2

second list- 1->3

output - 1->3->4->2

Hope you got the point..

please comment if there is anything wrong!!

by (189 points)