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

*program is in c* Implement the following functions for linked lists. You can as

ID: 3831658 • Letter: #

Question

*program is in c*

Implement the following functions for linked lists. You can assume that all the nodes in the linked list are distinct and each node appears in the list at most once. node *delete(node *head, int k) node *recursivedelete(node *head, int k) delete deletes the node with info k from the linked list and returns the new linked list. It returns the linked list without modification if k does not appear in the list. recursivedelete Ls a recursive function that deletes the node with info k from the linked list and returns the new linked list. It returns the linked list without modification if k does not appear in the list.

Explanation / Answer

node *delete(node *head, int k)
{
node *temp = head;
if(temp == null)
return head;
if(temp->info == k)
{
head = head->next;
free(temp);
return head;
}
node *prev = null;
while(temp != null && temp->info != k)
{
prev = temp;
temp = temp->next;
}
if(temp == null)
{
return head;
}
else
{
prev->next = temp->next;
free(temp);
}
}

node *recursivedelete(node *head, int k)
{
if(head == null)
return head;
if(head->info == k)
{
node *temp = head;
head = head->next;
free(temp);
return head;
}
recursivedeleteHelper(head, k);
return head;
  
}

void recursivedeleteHelper(node *n, int k)
{
if(n == null)
return;
  
if(n->next != null && n->next->info == k)
{
node *temp = n->next;
n->next = n->next->next;
free(temp);
return;
}
else
{
recursivedeleteHelper(n->next, k);
}
}