C function to find and delete a node from a singly linked list
The neatest way to deal with this is to use what I was taught as the "2 pointer trick" (thank you Charles Lindsay all those years ago):

Instead of holding a pointer to the record you hold a pointer to the pointer that points to it - that is you use a double indirection. This enables you to both modify the pointer to the record and to modify the record without keeping track of the previous node.

One of the nice things about this approach is that you don't need to special case dealing with the first node.

An untested sketch using this idea for delete_item (in C++) looks like:

void delete_item(node** head, int i) {
  for (node** current = head; *current; current = &amp;(*current)-&gt;next) {
    if ((*current)-&gt;x == i) {
      node* next = (*current)-&gt;next;
      delete *current;
      *current = next;
      break;
    }
  }
}


This loop will break after the first entry it finds, but if you remove the "break" then it will remove all entries that match.