Merger - 20%
This question relies on the following linked list structure
struct node {
const char *id;
struct node *next;
};
Each node is created as part of a singly linked list. The identifier is a C string. There are no sentinel nodes. NULL represents an empty list.
Merge two linked lists.
struct node * merge_lists(struct node *a, struct node *b);
Given two linked lists, you are to merge these two lists into a single one and return the head of the linked list.
The merge operation alternates between nodes of lists a and b in the order a_1, b_1, a_2, b_2,
a_3, b_3 etc.
If the lists are of unequal length, the remaining nodes are used in the longer list e.g. a is longer than b, then it would return a_1, b_1, a_2, b_2, a_3, b_3, a_4, a_5, a_6
Notes
No allocation, nor deallocation, of nodes, or C strings are necessary in this problem. malloc/free are not permitted.
Assume that a and/or b, as heads of the linked list.
If both lists a and b are NULL, NULL is returned. If list a or b are NULL, then they are equivalent to a zero length list and merge should proceed as described.
There are no guarantees about the value of id for any node in this part.
Helper functions are permitted.