I'm looking for the most commonly used style for writing the delete()delete_item() function fromof a singysingly linked list, that find a matching item and deletes it. Is what I have the 'typical' or 'normal' solution? Are there more elegant ones?
What seems unelegantinelegant to me about my solution below, although I don't know a better way to express it, is that you needthe code needs to check the first record individually (i.e. a special case), then as you iterate you're really looking at iter->nextit goes through the iteration, it's not checking iter, it's checking iter->next, ahead of yourthe iterator's present location, because in a singly linked list you can't go backwards.
So, is there a cleaner way to write the delete_item()delete_item() function?
This is incidently a complete example that can be compiled and tested. The output: