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

TTAI ATTENTION! Your Name TA\'s Name: 13.(25 pts) Write a C function zemoveAl10c

ID: 3882251 • Letter: T

Question

TTAI ATTENTION! Your Name TA's Name: 13.(25 pts) Write a C function zemoveAl10courrences () for a dynamic singly-finked list that has the following header: int removeAlloccurrences (Node **pList, char "pSearehSte)a The function should remove (free) all occurrences of nodes that contain dats that match the string pointed to by pšearchStr. If at least one match i s found, then the function returns 1, otherwise the function returns 0. Assume that struet node is defined as follows: typedof struct node char data[100] / This will be used to store strings struct node -pNext ; J Node wall Corra c pt mod S Instructor: Andrew S. O'Fallon Page 7 of 9

Explanation / Answer

int removeAllOccurences(Node **pList , char*pSearchStr) {

Node* curr = *pList, *prev;
int found = 0;

//Search if the element is present in head
    while (curr != NULL && !strcmp(curr->data , pSearchStr) )

    {

        *pList = curr->next;   // We need to change the head

        free(curr);               // free the old head

        curr = *pList;         // Change Curr

found = 1;

    }

    // Delete al other occurrences apart from head

    while (curr != NULL)

    {

        // Find for the key to be deleted

        while (curr != NULL && strcmp(curr->data ,  pSearchStr) )

        {

            prev = curr;

            curr = curr->next;

        }

        // If the data was not present in list

        if (curr == NULL)
  return found;

        // Remove node from linked list

        prev->next = curr->next;

found = 1;

        free(curr); // Free memory

        //Update Curr for next run

        curr = prev->next;

    }
}



Thanks, let me know if there is any concern.