Question: This question is a three parter question that refers to the struct in C language. Thank you for your time. A linked list of integers
This question is a three parter question that refers to the struct in C language. Thank you for your time.
A linked list of integers is built using the following struct: struct node { int data; struct node *next; }; 1. Write the definition of a function with the following prototype: void add(struct node* a[], int index, int value); The first argument is an array of lists (i.e., an array of struct node pointers, each of which points to the head of a list). The second argument is an index into the array, and the third argument is a value to be added. This function inserts the specified value at the head of the indexed list. There is no return value. Example: add(a, 3, 10) prepends a node containing the integer 10 to the list stored in element 3 of array a.
2. Suppose we have a list of integers. Each node of the list is defined as: struct node { int data; struct node * next; }; Write a function that takes in a list and returns the sum of all of the integers. The declaration of the function is: int sum(struct node * list);
3. Define a function named prepend that creates a new node and adds it to the beginning of a list. The function takes two parameters. The first parameter is a struct node * that points to the head of a list. (This pointer may be NULL.) The second parameter is an integer, which is the value to be stored in the new node. The function returns a pointer to the new list.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
