0% found this document useful (0 votes)
11 views19 pages

Linked List

Uploaded by

Kim Sunoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views19 pages

Linked List

Uploaded by

Kim Sunoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

LINKED LIST

CC214 – Data Structures and Algorithms


LINKED LIST
 A linked list, in simple terms, is a
linear collection of data elements.
 These data elements are called
nodes.
 Acts as a building block to
implement data structures such as
stacks, queues, and their variations
 Can be perceived as a train or a
sequence of nodes in which each
node contains one or more data
fields and a pointer to the next node.
TYPES OF
LINKED LIST
 Singly Linked List
 Circular Linked List
 Doubly Linked List
 Circular Doubly Linked
List
 Header Linked List
 Multi-linked list
YOUR GUIDE…
 Every node contains two parts, and integer (or
any data type) and a pointer to the next node.
 A Node is a data structure that stores a value
that can be of any data type and has a pointer to
another node.
 The last node will have no next node connected
to it, so will store a special valued called NULL
(represented by X).
 The None (Null) denotes the end of the list.
 Linked List contains the variable HEAD (START,
BEGIN) that stores the address of the first nodes.
So, if the object start is null, then the lined list is
empty.
TEMPLATE FOR THE NODE Value of a nodeLink to the other node

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

head current current current current current


INSERTING A
NODE BEFORE A
GIVEN NODE
 adding a new node
immediately before
the specified node.
 This operation is
commonly used to
add elements or data
into a linked list at a
specific position.
INSERTING A NODE BEFORE
A GIVEN NODE
7 4 2 5 9 10 X
pre_current
curren pre_current
curren pre_current
curren curren
head
pre_current
curren t t t t
t
DELETE
 First node
 Last node
 Given node
DELETE AT THE END
4 2 5 9 X 10 X

head pre_current current

Check if the head is null

You might also like