Advertisements
Advertisements
प्रश्न
Explain a linked list with suitable example having six nodes with properly labeled diagram.
कोड लेखन
स्पष्ट करा
Advertisements
उत्तर
A Linked List is a linear data structure in which elements are not stored in contiguous memory locations. Each element, called a node, contains two parts:
- Data – stores the value
- Next (Link/Pointer) – stores the address of the next node
The last node points to NULL, indicating the end of the list.
struct Node
{
int data;
Node* next;
};
Example: Linked List with Six Nodes
Let us create a linked list containing six values:
10, 20, 30, 40, 50, 60
Properly Labeled Diagram
HEAD
|
v
+-----+------+ +-----+------+ +-----+------+ +-----+------+ +-----+------+ +-----+------+
| 10 | next |-->| 20 | next |-->| 30 | next |-->| 40 | next |-->| 50 | next |-->| 60 | NULL |
+-----+------+ +-----+------+ +-----+------+ +-----+------+ +-----+------+ +-----+------+
Node 1 Node 2 Node 3 Node 4 Node 5 Node 6
(Data:10) (Data:20) (Data:30) (Data:40) (Data:50) (Data:60)
Explanation of the Diagram
- HEAD stores the address of the first node.
- Each node has two fields:
- Left part → Data
- Right part → Next pointer
- Each node points to the next node in sequence.
- The last node points to NULL, showing the end of the list.
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2024-2025 (July) Official Board Paper
