data-structures Linked List Singly Linked List


Example

Singly Linked Lists are a type of linked list. A singly linked list's nodes have only one "pointer" to another node, usually "next." It is called a singly linked list because each node only has a single "pointer" to another node. A singly linked list may have a head and/or tail reference. The advantage of having a tail reference are the getFromBack, addToBack, and removeFromBack cases, which become O(1).

         ┌─────────┬─────────┐   ┌─────────┬─────────┐         
 HEAD ──▶│  data   │"pointer"│──▶│  data   │"pointer"│──▶ null 
         └─────────┴────△────┘   └─────────┴─────────┘         
          SINGLE        │                                      
          REFERENCE ────┘                                                                

Example Code in C

Example Code in Java, with unit tests - singly linked list with head reference