I really like memes and there is one for every situation. I remember trying to look for one recently that had something on "we do not do that here", luckily I was able to pull it out from my gallery. The act of scrolling from one meme to another is a real-life example of linked lists.
A linked list is a linear data structure that includes a series of connected nodes that store data and the address of the next node.
Representation of Linked lists
Every node in a linked list contains:
-
a data item
-
address of the next node
Types of Linked Lists
-
Singly-linked list: where every node has data and pointer to the following node
-
Doubly linked list: where a pointer is added to the previous node. Meaning we can move in either direction
-
Circular linked list: where the last element is linked to the first element causing a circular loop.
A circular linked list can be doubly or singly linked.
In a singly circular linked list, the following pointer of the last item points to the first item, while in a doubly-linked list the previous pointer of the first item points to the last item.
Linked List Operations
Search: finds a node in the linked list
Traversal: touching each element of the linked list
Sort: ordering the nodes of the linked list
Insertion: adding a new element to the linked list
Deletion: removes an element in the linked list
Linked List Application
Linked lists are used in:
-
Other data structures like queues and stacks.
-
Dynamic memory allocation
-
Maintaining a directory of names
-
Performing arithmetic operations on long integers