Create a linked list and add a function to merge 2 singly Linked Lists according to following rules.
Insert nodes of 2nd linked list into 1st linked list at alternate position of first list.
For Example :
List 1 : 5-> 7 -> 17 -> 13 -> 11
List 2: 12 -> 10 -> 2 -> 4 -> 6
.Output :
List 1: 5 -> 12 -> 7 -> 10 -> 17 -> 2 -> 13 -> 4 -> 11 -> 6
List 2: Empty
its not working!I am entering 1,2,3,4,5, for the first link list and 6,7,8,9,10 for the second. the resulting answer must be 1,6,7,3,8,4,9,5,10....BUT ITS BREAKING
Use parameters as Salem C suggested in your other post.
Line 90: x should be y
Print the original lists. You'll discover that there's a bug in showdata().
You need another local variable to point to the unlinked item.
Draw out two lists with the the pointers to the next items.
Now pick a source and destination item from the lists. Suppose you need to insert the source after the destination. Using a different colored marker, draw the new pointers.
Use your diagram to write the code.
There are some special cases to deal with:
1. What if head1 is empty? Just return head2
2. What if you one list is longer than the other?