Linked List
Linked List
LINEAR NONLINEAR
ARRAY
TREES&
LINKLIST STACK
QUEUE GRAPH
Linked list
Linked list is a linear data structure. It contains nodes. Each
node contains two parts, i.e. DATA part and LINK part.
The data contains elements and
Link contains address of another node.
Node
Data Link/Address
Start
25 10 15 /
10
START
14 08 30 10 42 N
05 08 10
• Suppose you are writing a program which will store marks of 100
students in math's. Then our logic would be like this during compile
time –
• int marks[100];
• Now at run time i.e. after executing program if number of students are
101 then how you will store the address of 101th student ?
• Or if you need to store only 40 students then again you are wasting
memory unnecessarily.
• Using linked list you can create memory at run time or free memory at
run time so that you will able to fulfil your need in efficient manner.
Types of Linked Lists
Start
First
First
First
START
Node A Node B
Insert into a Linked List
START
Node A Node B
START
(a). Before Insertion
Node A Node B
------------------------
Node N
START
Data list
Node A Node B
AVAIL
Node N
Free-storage list
Insert into a Linked List
START
Data list
Node A Node B
------------------------
AVAIL
Node N
....
Free-storage list
Insert into a Linked List
START
Node A Node B
START
(a). Before Deletion
AVAIL
------
------
------
------
------
------
--- ....
Free-storage list
Deletion from a Linked List