Linked List
Linked List
Value of a node
node
Link to the other node
SINGLY-LINKED
LIST
Simplest type of linked
list in which every node
contains some data and
a pointer to the next
SINGLY- node of the same data
LINKED type.
LLIST
A singly linked list allows
traversal of data only in
one way.
SINGLY-LINKED
LISTS -
INSERTING
The new node is inserted
at the beginning
The new node is inserted
at the end
The new node is inserted
before the given node
The new node is inserted
after the given node.
LET’S CREATE A TEMPLATE
FOR THE SINGLY LINKED
LIST
INSERTING AT THE
BEGINNING
How it works?
10 X
new_node
head
9 X 10 X
head
new_node head
4 X 2 5 9 10 X
head
new_node head
INSERTING AT THE
BEGINNING
Insert the number 7 in the list
1. Create a new node
INSERTING AT THE
BEGINNING (CONT…)
2. Check if the head has a value of null
2.1 If the head has a value of null
7 X
head
new_node
INSERTING AT THE
BEGINNING (CONT…)
2. Check if the head has a value of null
2.2 If the head is not null
7 X 4 2 5 9 10 X
new_node
hea hea
d d
TRAVERSING
Traversing a linked
list means accessing
the nodes of the list
in order to perform
some processing on
them.
TRAVERSING