Skip to content

Instantly share code, notes, and snippets.

@nikmis
Created July 20, 2012 04:52
Show Gist options
  • Select an option

  • Save nikmis/3148769 to your computer and use it in GitHub Desktop.

Select an option

Save nikmis/3148769 to your computer and use it in GitHub Desktop.
Delete Node from Singly Linked List
typedef struct list
{
int item;
struct list *next;
} list;
/* l - Head of the list
* node - Node to be deleted from the list.
*/
void listDeleteByNode(list **l, list *node)
{
if(emptyList(*l))
return;
list *n = node->next;
/* Check if there's only one node in the list */
if(emptyList(n))
{
*l = n;
free(node);
}
else
{
node->item = n->item;
node->next = n->next;
free(n);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment