Linked List Code Snippets

Linked List

Created: 2022-06-29
Tags: #permanent


Abstract

  • ADDING nodes to a linked list
  • REMOVING nodes of a linked list
  • FREEING the linked list
    All codes are checked by valgrind and are memory bug free.

Freeing the linked list

ITS IMPORTANT TO FREE ALL NODES!
Don't simply do this free(linked_list_name). That will only free one block of memory!!

Do this instead:

while (linked_list_name != NULL)
    {
        node *tmp = linked_list_name->next;
        free(linked_list_name);
        linked_list_name = tmp;
    }

References