The Gateway to Computer Science Excellence
0 votes
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 sorted linked lists into final sorted linked list

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

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

1 Answer

+3 votes

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)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,648 questions
56,430 answers
195,209 comments
99,924 users