Question: Present a function to merge two linked lists and produce one list. Given two lists, your function must merge them in such a way that

Present a function to merge two linked lists and produce one list. Given two lists, your function must merge them in such a way that it interleaves one element from each list alternatively to produce the final list. For example, consider a linked list such as 1 rightarrow 2 rightarrow 3 rightarrow 4 rightarrow 12 rightarrow 19 rightarrow NULL with a pointer "firstList" pointing to its first element (1), and another list such as 8 rightarrow 7 rightarrow 6 rightarrow 5 rightarrow NULL with a pointer "secondList" pointing to its first element (8), your function produces 1 rightarrow 8 rightarrow 2 rightarrow 7 rightarrow 3 rightarrow 6 rightarrow 4 rightarrow 5 rightarrow 12 rightarrow 19 rightarrow NULL, with the "firstPointer" now pointing to the first element of this new list (1). The idea is to merge both lists by taking one element from each at any time; in case you exhaust one list, you simply append elements from the other list until you have considered all elements. In other words, implement void mergeLinkedList (chunk *firstList, chunk* secondList)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
