Question: Please write this function in C: (void add_lists(Node *list1, Node *list2)) The function add_lists should add the value of each node contained in the same

Please write this function in C:

(void add_lists(Node *list1, Node *list2))

The function add_lists should add the value of each node contained in the same position in the lists together and store the result as the new value of list1s node at that position. If list1 is shorter than list2 or vice versa, than for nodes past the shorter of the two lists no addition needs to occur (and list1 should remain the same for these nodes). Use recursion to create this function.

Please write this function in C: (void add_lists(Node *list1, Node *list2)) The

function add_lists should add the value of each node contained in the

Expected Output:

same position in the lists together and store the result as the

new value of list1s node at that position. If list1 is shorter

Please use recursion to write the function.

#include #include #include #include typedef struct node { int value; struct node *next; } Node; void print_list(Node *head); Node* insert_at_head (Node *head, int new_value); void add_lists(Node *list1, Node *list2);|| int main() { printf(" add_list test "); printf(" ** "); Node *listi, *list2, *list3, *list4, *lists, *listo; listi list2 list3 list4 lists listo NULL; // make ALL Lists empty for (int i 1; i = 4; i--) list2 = insert_at_head(list2, i); printf(" List 1... "); print_list(list1); printf(" List 2... "); print_list(list2); printf(" List 1 after add... "); add_lists(listi, list2); print_list(listi); for (int i 1; i value new_value; new_node->next NULL; if (head NULL) return new_node; else { new_node->next head; return new_node; } } void print_list(Node *head) Node *current; current head; int i = 0; while (current != NULL) { printf("Node %d: %d ", i, current->value); current = current->next; i++; } 7 add_list test List 1... Node 0: 5 Node 1: 4 Node 2: 3 Node 3: 2 Node 4: 1 List 2... Node 0: 4 Node 1: 5 Node 2: 6 Node 3: 7 Node 4: 8 List 1 after add... Node 0: 9 Node 1: 9 Node 2: 9 Node 3: 9 Node 4: 9 List 3... Node 0: 2 Node 1: 1 List 4... Node 0: 7 Node 1: 6 Node 2: 5 Node 3: 4 List 3 after add... Node 0: 9 Node 1: 7 List 5... Node 0: 7 Node 1: 6 Node 2: 5 Node 3: 4 List 6... Node 0: 2 Node 1: 1 List 5 after add... Node 0: 9 Node 1: 7 Node 2: 5 Node 3: 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!