Linked List ek important data structure hai jo DSA roadmap ka core part hai. Agar aap coding ya placements ki preparation kar rahe hain, to Linked List samajhna bahut zaroori hai. Ye ek linear data structure hai jahan elements memory me continuous nahi hote, balki nodes ke form me linked hote hain.
Array ke opposite, Linked List dynamic hoti hai aur memory efficiently use karti hai. Isi wajah se interviews aur real-world applications me iska use kaafi zyada hota hai.
Agar aap beginner hain, to pehle DSA Roadmap for Beginners follow karein jisse aapko poora learning path milega.
Linked List ek collection hoti hai nodes ki. Har node me do parts hote hain:
Data
Pointer (Next)
Pointer next node ka address store karta hai, jisse nodes ek chain me connected rehte hain.
Node ka structure kuch aisa hota hai:
struct Node {
int data;
struct Node* next;
};
👉 Yaha “data” value store karta hai
👉 “next” next node ka address store karta hai
Har node next node ko point karta hai
Har node previous aur next dono ko point karta hai
Last node first node ko point karta hai
Linked List:
10 → 20 → 30 → 40
👉 Har element next element se connected hai
👉 Last node ka next = NULL
#include <iostream>
using namespace std;
class Node {
public:
int data;
Node* next;
Node(int val) {
data = val;
next = NULL;
}
};
// Insert at Beginning
void insertAtBeginning(Node* &head, int val) {
Node* newNode = new Node(val);
newNode->next = head;
head = newNode;
}
// Insert at End
void insertAtEnd(Node* &head, int val) {
Node* newNode = new Node(val);
if (head == NULL) {
head = newNode;
return;
}
Node* temp = head;
while (temp->next != NULL) {
temp = temp->next;
}
temp->next = newNode;
}
// Delete from Beginning
void deleteAtBeginning(Node* &head) {
if (head == NULL) {
cout << "List is empty\n";
return;
}
Node* temp = head;
head = head->next;
delete temp;
}
// Delete by Value
void deleteByValue(Node* &head, int key) {
if (head == NULL) return;
// If head needs to be deleted
if (head->data == key) {
Node* temp = head;
head = head->next;
delete temp;
return;
}
Node* temp = head;
while (temp->next != NULL && temp->next->data != key) {
temp = temp->next;
}
if (temp->next == NULL) {
cout << "Value not found\n";
return;
}
Node* nodeToDelete = temp->next;
temp->next = temp->next->next;
delete nodeToDelete;
}
// Search element
bool search(Node* head, int key) {
Node* temp = head;
while (temp != NULL) {
if (temp->data == key)
return true;
temp = temp->next;
}
return false;
}
// Display Linked List
void display(Node* head) {
Node* temp = head;
while (temp != NULL) {
cout << temp->data << " -> ";
temp = temp->next;
}
cout << "NULL\n";
}
int main() {
Node* head = NULL;
// Insert elements
insertAtBeginning(head, 5);
insertAtEnd(head, 10);
insertAtEnd(head, 20);
insertAtEnd(head, 30);
cout << "Linked List: ";
display(head);
// Delete operations
deleteAtBeginning(head);
cout << "After deleting first node: ";
display(head);
deleteByValue(head, 20);
cout << "After deleting value 20: ";
display(head);
// Search
if (search(head, 10))
cout << "10 found in list\n";
else
cout << "10 not found\n";
return 0;
}
👉 Ye basic structure aur traversal dikhata hai
Beginning me
End me
Middle me
First node
Last node
Specific node
List ko print karna
Operation Complexity
Insertion O(1)
Deletion O(1)
Search O(n)
👉 Linked List insertion aur deletion me fast hoti hai
Dynamic size (fixed nahi hota)
Memory efficient
Easy insertion/deletion
Random access possible nahi
Pointer handling complex hota hai
Extra memory required
Feature Array Linked List
Memory Continuous Non-continuous
Size Fixed Dynamic
Access Fast Slow
Dynamic memory allocation
Implementing stacks and queues
Music playlist
Browser history
NULL pointer handle na karna
Memory allocation bhool jana
Pointer galat link karna
👉 Tip: Diagram banake samjho
Concept clear karo
Code likho (insert, delete)
Dry run karo
15–20 questions solve karo
👉 Ye sab topics milkar aapki DSA strong banate hain
Linked List ek powerful data structure hai jo aapko dynamic data handling sikhata hai. Agar aap DSA roadmap follow kar rahe hain, to Linked List aapke liye next important step hai.
Practice aur concept clarity ke saath aap Linked List ko easily master kar sakte hain aur coding interviews ke liye ready ho sakte hain.
👉 Complete Roadmap:
https://sites.google.com/view/dsarop/
👉 Next Topic: Binary Search