Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Function to find the given item number and delete it in KnightsMartRestockProduct list.
- void deleteNodeRestockList(struct KnightsMartRestockProduct **head_ref, int key) {
- // Store head node
- struct KnightsMartRestockProduct *temp = *head_ref, *prev;
- // If head node itself holds the key to be deleted
- if (temp != NULL && temp->itemNum == key) {
- *head_ref = temp->next; // Changed head
- free(temp); // free old head
- return;
- }
- // Search for the key to be deleted, keep track of the
- // previous node as we need to change 'prev->next'
- while (temp != NULL && temp->itemNum != key) {
- prev = temp;
- temp = temp->next;
- }
- // If key was not present in linked list
- if (temp == NULL) return;
- // Unlink the node from linked list
- prev->next = temp->next;
- free(temp); // Free memory
- }
Add Comment
Please, Sign In to add comment