Guest User

Untitled

a guest
Jan 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. //Removes an (single?) employee of the given lastName or SIN number
  2. void removeEmployee(struct Node** head, char firstName [256], int sinNum){
  3.     if (*head == NULL)
  4.         return;
  5.     struct Node* current = *head;
  6.     struct Node* prev = current;
  7.     struct Node* temp = NULL;
  8.    
  9.     do{
  10.         //if one of the other is true don't need to check which one the user wants to use because they will not equal anywyas
  11.         if (current->employee->sinNumber == sinNum || strcmp(current->employee->firstName, firstName) == 0){
  12.             //current node is the head
  13.             if (current == *head){
  14.                 temp = *head;
  15.                 *head = (*head)->next;
  16.             }
  17.             //current node is the tail
  18.             else if (current->next = NULL){
  19.                 temp = currnet;
  20.                 prev ->next = NULL;
  21.             }
  22.             //current node is in the middle
  23.             else {
  24.                 temp = current; //holds the node to be freed
  25.                 prev->next = current->next; //deletes the employee
  26.             }
  27.         }
  28.         free(temp->employee);
  29.         free(temp);
  30.         prev = current;
  31.         current = current->next;
  32.     }while(current->next!=NULL);
  33. }
Add Comment
Please, Sign In to add comment