Guest User

Untitled

a guest
Feb 17th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. //Function to find the given item number and delete it in KnightsMartRestockProduct list.
  2. void deleteNodeRestockList(struct KnightsMartRestockProduct **head_ref, int key) {
  3. // Store head node
  4. struct KnightsMartRestockProduct *temp = *head_ref, *prev;
  5.  
  6. // If head node itself holds the key to be deleted
  7. if (temp != NULL && temp->itemNum == key) {
  8. *head_ref = temp->next; // Changed head
  9. free(temp); // free old head
  10. return;
  11. }
  12.  
  13. // Search for the key to be deleted, keep track of the
  14. // previous node as we need to change 'prev->next'
  15. while (temp != NULL && temp->itemNum != key) {
  16. prev = temp;
  17. temp = temp->next;
  18. }
  19.  
  20. // If key was not present in linked list
  21. if (temp == NULL) return;
  22.  
  23. // Unlink the node from linked list
  24. prev->next = temp->next;
  25.  
  26. free(temp); // Free memory
  27. }
Add Comment
Please, Sign In to add comment