Xadez

DeleteElement

May 26th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. void DeleteElement(Node **head, char *director)
  2. {
  3.     if (*head == NULL)
  4.     {
  5.         printf("The list is empty!\n");
  6.         return;
  7.     }
  8.  
  9.     Node *current = *head;
  10.     Node *previous = NULL; //For 1st node, indicate there is no previous.
  11.  
  12.     while (current != NULL)
  13.     {
  14.         if (strcmp(director, current->data.producer) == 0)
  15.         {
  16.             if (previous == NULL)
  17.             {
  18.                 *head = current->next;
  19.             }
  20.             else
  21.             {
  22.                 previous->next = current->next;
  23.             }
  24.            
  25.             free(current);
  26.  
  27.             printf("Елемента е изтрит успешно.\n");
  28.  
  29.             current = *head;
  30.         }
  31.         else
  32.         {
  33.             previous = current;
  34.             current = current->next;
  35.         }  
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment