In this Article, we'll explore about LinkedList & its types and
Real-life Use Cases of LinkedList and Best Practice to use.
What is LinkedList ?
LinkedList as a linear data structure where elements are stored in nodes that are linked together by pointers, each containing the data and a reference to the next node. Unlike Arrays, Linked List elements are not stored at a contiguous location.
In a Node, there is data and address/reference of next node and last node always point to null.
As you can see in image below-
Types of linked lists
1- Singly-linked list :-In Singly-linked list, We can say that traversal of items can be done in the forward direction only due to the linking of every node to its next node.
Operation on Singly-Linked list
Insertion
Deletion
Search
Display
Below you can see representations-
Node Creation-
struct node {
int data; // Data
struct node * next; // Address
};
2- Doubly-linked list :- In Doubly-linked list, We can say that Traversal of items can be done in both forward and backward directions as every node contains an additional prev pointer that points to the previous node.
Operation on Doubly-Linked list
Insertion
Deletion
Display
Representation of Doubly linked list-
Node Creation-
// Class for Doubly Linked List
public class DLL {
Node head; // head of list
/* Doubly Linked list Node*/
class Node {
int data;
Node prev;
Node next;
// Constructor to create a new node
// next and prev is by default initialized as null
Node(int d) {
data = d;
}
}
}
3- Circular linked lists :- In Circular linked list, We can say that A circular linked list is a type of linked list in which the first and the last nodes are also connected to each other to form a circle, there is no NULL at the end.
Operation on Circular Linked list
Insertion
Deletion
Display
Representation of Circular linked list-
Real-life Use Cases of LinkedList
find various applications in real-life scenarios due to their dynamic memory allocation and efficient insertion and deletion operations. Here are some real-life use cases of LinkedLists:
Music and Video Playlists
In music and video streaming services, playlists are commonly implemented using LinkedLists. Each song or video is represented as a node, allowing users to easily add, remove, or rearrange the sequence of media items in their playlists.
Browser History in Web Browsers
Web browsers use LinkedLists to maintain a user's browsing history. Each visited web page is stored as a node, enabling users to navigate backward and forward through their browsing history, facilitating a seamless browsing experience.
Task Management Applications
Task management applications often utilize LinkedLists to manage to-do lists. Each task is stored as a node, enabling users to add new tasks, mark tasks as complete, or reorder tasks based on priority or due dates.
Scheduling Systems
In transportation systems, such as train or flight or Bus scheduling, LinkedLists can be used to manage the sequence of upcoming departures. Each departure schedule is stored as a node, allowing for easy rearrangement and adjustment of the schedule based on real-time changes or delays.
Top comments (0)