Question: 20. Write the following function: struct node insertBefore(st ruct node 1ist, int nb, int n) The list parameter points to a linked list of the

20. Write the following function: struct node insertBefore(st ruct node 1ist, int nb, int n) The list parameter points to a linked list of the following structure struct node int value struct node nexti The function should insert a new node containing value n before the node containing value nb. If the list contains multiple node with value nb then insert before the first node containing nb. The function should return a pointer to the head of the linked list The function does not modify the list if the list does not have a node containing value nb. struct node 'insertBeforelstruct node list, int nb, int n) struct node new node; struct node prev, cur; new node mallocisizeof lstruct node) if (new node NULL) printf("Brror malloc failed in add to listin") return list: new_node->value n; =
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
