Linked List Data Structure
Introduction to Linked List
A LinkedList is a linear data structure in which elements are stored in nodes, and each node points to the next node, forming a chain. Imagine a train where each car is connected to the next car, but you can only move forward through the train. Each car contains passengers (data) and has a coupling (pointer) that connects it to the next car.
Video Explanation

Definition and Structure
A linked list consists of nodes, where each node contains:
- Data: The value stored in the node.
- Next: A reference to the next node in the sequence (or
nullif there is no next node).
The sequence starts from a node called the head and continues until it reaches a node that points to null, which marks the end of the list.
Properties
Key characteristics of linked lists include:
-
Dynamic Size: Unlike arrays, linked lists can grow and shrink dynamically as nodes are added or removed.
-
Sequential Access: Accessing elements in a linked list requires traversal from the head, as elements are not indexed like in an array.
Head -> A -> B -> C -> D -> null
Types of Linked Lists
-
Singly Linked Lists: Each node has a reference to the next node in the sequence.
Example:
Head -> 10 -> 20 -> 30 -> null -
Doubly Linked Lists: Each node has two references—one to the next node and one to the previous node.
Example:
Head <-> 10 <-> 20 <-> 30 <-> null -
Circular Linked Lists: The last node points back to the head, forming a circular structure.
Example:
Head -> 10 -> 20 -> 30 --||-----------------| -
Doubly Circular Linked Lists: Similar to a circular linked list but with both next and previous references.
Example:
Head <-> 10 <-> 20 <-> 30 <-> Head

LinkedList Operations
A LinkedList typically supports the following operations:
- Insert at the Beginning:
- A new node is created with the given data.
- The new node's next pointer is set to the current head. - The head pointer is updated to point to the new node.
- Insert at the End:
- If the list is empty, the new node becomes the head.
- Otherwise, traverse the list until the last node is found, and set its next to the new node.
- Delete Node by Value:
- If the head contains the key, adjust the head to point to the next node. -Otherwise, traverse the list to find the node before the target node and adjust its next pointer to skip the target node.
- Search for a Node:
- Traverse the list while comparing each node’s data with the key.
- If a match is found, return True; otherwise, after reaching the end of the list, return False.
- Traverse and Print the List: -Traverse the list, printing the data in each node until the end of the list (NULL) is reached.