Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A linked list of integers is built using the following struct: struct node { int

ID: 3607623 • Letter: A

Question

A linked list of integers is built using the following struct:
struct node {
  int data;
  struct node *next;
};
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.

All I need is the function.

Explanation / Answer

Please find below implementaion of linked list.

// A linked list node
struct node
{
int data;
struct node *next;
};

void add(struct node* a[], int index, int value)
{

if(index < 0)
return;

// creating new node
struct *newNode = (struct node *)malloc(sizeof(struct node));
newNode->data = value;

// adding new node at head
newNode->next = a[0];
a[0] = newNode;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote