5..linked List
5..linked List
Linked Lists
(Chapter-4)
Ref: Schaum's Outline Series, Theory and problems of Data Eftekhar Hossain
Structures
By Seymour Lipschutz Assistant Professor
Dept. of ETE, CUET
And Online Resource
1
Topics to be Covered
Difference between array and linked list
Types of Linked List
Singly Linked List
Operations on Linked list
2
Introduction
Suppose we want to arrange the name of the students according
to the first letter of their names
Mick, Jhon, Alpha, Mark, Rock , Tony
We can do this in two ways
Two Ways
3
Example
We want to store a list of numbers : 23, 44, 87, 96
23 44 87 96
4
Example
1000
Head
Nodes are scattered here and there in memory but they are still
connected with each other.
Linked List is the link representation of List
5
Limitations of Arrays
Arrays have a fixed dimension.
6
Linked List
Linked list is a linear data structure.
Each node contains two parts, i.e. DATA part and LINK part.
Node
10
Single Linked List (SLL)
A single linked list is one in which all the nodes are linked
together in some sequential manner .
First
11
Circular Singly Linked List
A circular linked list is one which has no beginning and no ending.
The null pointer in the last node of a linked list is replaced with the
address of its first node such a list is called circular linked list.
12
Double Linked List
A single linked list has some disadvantages
That it can traverse it in one direction.
Prev data Next
Many applications require searching
backward and forward travelling
A doubly linked list is divided into three parts When each node is
divided into three parts.
They are two link parts and one data part.
14
Operations on Linked List
Deletion operation is used to delete on item from the linked list. It
may be deleted from the beginning of a linked list, specified
position in the list.
If we start traversing from the very first node towards the last node
, It is called forward traversing.
If the traversal start from the last node towards the first node , it is
called backward traversing.
15
Inserting a node in SLL
There are 3 cases here:-
Insertion at the beginning
Insertion at the end
Insertion after a particular node
16
Inserting a node at beginning
17
Inserting a node at the end
Here we simply need to make the next pointer of the last node
point to the new node
18
Inserting after an element
Here we again need to do 2 steps :-
Make the next pointer of the node to be inserted point to the next node of the
node after which you want to insert the node
Make the next pointer of the node after which the node is to be inserted,
point to the node to be inserted
19
Deleting a node in SLL
Here also we have three cases:-
Deleting the first node
Deleting the last node
Deleting the intermediate node
20
Deleting the Last node
Here we apply 2 steps:-
Making the second last node’s next pointer point to NULL
Deleting the last node via delete keyword
21
Deleting a particular node
Here we make the next pointer of the node previous to the node
being deleted ,point to the successor node of the node to be deleted
and then delete the node using delete keyword
22
Advantages of Linked lists
We can dynamically allocate memory space as needed.
23
Thank You
24