SlideShare a Scribd company logo
Linked List
VARIOUS TYPES OF LINKED LIST
able of Contents
 Circular Linked List
 Linked Implementation of Stack
 Linked Implementation of Queue
Application of Linked List
Concept of Linked List
 Linked list is a linear data structure.
 A Linked List is a set of nodes where each node has two fields ‘data’
and ‘link’.
DATA LINK
 Piece of Information
Data Type : Int,char,float etc.
Used to point to next node
C Representation of Simple Linked List
 C structure for creating a node in a Linked List :
typedef struct node
{
int data;
struct node *next;
}NODE;
Stores Information part of data
Stores address of next node
Circular Linked List
 Circular linked list is a sequence of elements in which every element
has link to its next element in the sequence and the last element has
the link to the first element in the sequence.
 The circular linked list is as shown below :
10 20 30 40 50
Head Node
Operation performed on Circular Linked List
 The following operation can be performed on Circular linked list.
1. Insertion
2. Deletion
3. Display
Insertion of Circular Linked list
 Algorithm:
Step 1: Create a new_node with a given value.
Step 2: Check whether list is empty (head==NULL).
Step 3: If empty, then head=new_node and new_node→next=head.
Step 4: If not empty then create a temp node pointer and initialize with
‘head’.
Step 5: Move temp node to its next node, until head node not achieved
(temp→next==head).
Step 6: Set new_node→next=head, head=new_node and
temp→next=head.
Inserting a node as a head node
 Algorithm:
Step 1: Create a new_node with a given value.
Step 2: Check whether list is empty (head==NULL).
Step 3: If empty, then head=new_node and new_node→next=head.
Step 4: If not empty then create a temp node pointer and initialize with
‘head’.
Step 5: Move temp node to its next node, until head node not achieved
(temp->next==head).
Step 6: Set temp→next=new_node and new_node→next=head.
Inserting a node as a last node
 Algorithm:
Step 1: Create a new_node with a given value.
Step 2: Check whether list is empty (head==NULL).
Step 3: If empty, then head=new_node and new_node->next=head.
Step 4: If not empty then create a temp node pointer and initialize with
‘head’.
Step 5: Define key value after which the node is to be inserted.
Step 6: Check for key value (temp→data==key).
Step 7: Every time check whether temp is reached to the last node or
not. If yes then print Node not found.
Step 8: If temp=key then check whether it is last node
(temp→next==head).
Step 9: If temp is last node then temp->next=new_node and
new_node→next=head.
Step 10: If temp is not last node then new_node→next=temp→next and
temp→next=new_node.
Inserting a node at specific location
Deletion of any node
 Algorithm:
Step 1: Check whether list is Empty (head == NULL).
Step 2: If it is Empty then, print list is empty.
Step 3: If it is Not Empty then, define two Node pointers 'temp1' and
'temp2' and initialize 'temp1' with head.
Step 4: Keep moving the temp1 until it reaches to the specified or to the
last node. And every time set 'temp2 = temp1' before moving the
'temp1' to its next node.
Step 5: If it is reached to the last node then display Node not found.
Step 6: If it is reached to the exact node which we want to delete, then
check whether list is having only one node (temp1→next == head).
Step 7: If list has only one node and that is the node to be deleted then
set head=NULL and delete temp1 (free(temp1)).
Step 8: If list contains multiple nodes then check whether temp1 is the
first node in the list (temp1 == head).
Step 9: If temp1 is the first node then set temp2 = head and keep
moving temp2 to its next node until temp2 reaches to the last node.
Then set head=head→next, temp2→next=head and delete temp1.
Step 10: If temp1 is not first node then check whether it is last node in
the list (temp1→next == head).
Step 11: If temp1 is last node then set temp2→next=head and delete
temp1 (free(temp1)).
Step 12: If temp1 is not first node and not last node then set
temp2→next = temp1→next and delete temp1 (free(temp1)).
Display Circular Linked List
 Algorithm:
Step 1: Check whether list is Empty (head == NULL).
Step 2: If it is Empty, then print list is empty.
Step 3: If it is Not Empty then, define a Node pointer 'temp' and
initialize with head.
Step 4: Keep displaying temp→data with an arrow (--->) until temp
reaches to the last node.
Step 5: Finally display temp→data with arrow pointing to head→data.
Advantages of Circular Linked list over Singly Linked
list
 In Circular linked list, the next pointer of last node in pointing to the
head node.
 Hence we can move from last node to the head node of the list very
efficiently.
 So, accessing of any node is much faster then singly linked list.
 The last node’s next pointer have null value in singly linked list while
in circular linked list it is having the address of the head node.
 Hence there is no loss of memory.
Linked Implementation of Stack
 Stack is a special case of list and therefore we can represent stack
using arrays as well as using linked list.
 The advantage of implementing stack using linked list is that we
need not have to worry about the size of the stack.
 Since we are using linked list as stack, we are inserting the nodes in
the stack and the size is dynamically changed. So there is not stack
full (Overflow condition).
C structure of Linked
Stack
Representation of Linked
Stack
struct stack
{
int data;
struct stack *next;
}NODE;
40
30
20
10 NULL
Top Node
Insert a node into Linked Stack
 We can insert the node using user defined function named
push(value).
 Algorithm:
 Step 1: Create a new_node with given value.
 Step 2: Check whether stack is Empty (top == NULL).
 Step 3: If it is Empty, then set new_node→next=NULL.
 Step 4: If it is Not Empty, then set new_node→next=top.
 Step 5: set top = new_node.
Delete a node from Linked Stack
 We can delete a node from linked stack using user defined function
called pop().
 Algorithm:
 Step 1: Check whether stack is Empty (top == NULL).
 Step 2: If it is Empty, then display “Stack is empty”.
 Step 3: If it is Not Empty, then define a Node pointer 'temp' and set it
to 'top'.
 Step 4: Then set 'top = top → next'.
 Step 5: Delete 'temp' (free(temp)).
Display Linked Stack
 Algorithm:
 Step 1: Check whether stack is Empty (top == NULL).
 Step 2: If it is Empty, then display “Stack is Empty”.
 Step 3: If it is Not Empty, then define a Node pointer 'temp' and
initialize with top.
 Step 4: Display 'temp → data --->' and move it to the next node.
Repeat the same until temp reaches to the first node in the stack
(temp → next != NULL).
 Step 5: Display 'temp → data ---> NULL'.
Linked Implementation of Queue
 We can implement queue using linked list.
 The main advantage is we need not have to worry about size of the
queue, so there will not be a queue full condition.
 The left most pointer is called front node and the right most pointer is
called rear node.
 We can not remove any arbitrary node from queue.
C structure of Linked
Queue
Representation of Linked
Queue
struct node
{
int data;
struct stack *next;
}Q;
40302010
Front
node
Rear
node
Insert a node into Linked Queue
 Algorithm:
 Step 1: Create a new_node and set new_node → next = NULL.
 Step 2: Check whether queue is Empty (rear == NULL)
 Step 3: If it is Empty then, set front = new_node and rear =
new_node.
 Step 4: If it is Not Empty then, set rear→next = new_node and rear =
new_node.
Delete a node from Linked Queue
 Algorithm:
 Step 1: Check whether queue is Empty (front == NULL).
 Step 2: If it is Empty, then display "Queue is Empty!!!”
 Step 3: If it is Not Empty then, define a Node pointer temp and set it
to front.
 Step 4: Then 'front = front → next' and delete 'temp' (free(temp)).
Display Linked Queue
 Algorithm:
 Step 1: Check whether queue is Empty (front == NULL).
 Step 2: If it is Empty then, display “Queue is Empty!!!”
 Step 3: If it is Not Empty then, define a Node pointer temp and
initialize with front.
 Step 4: Display temp → data ---> and move it to the next node.
Repeat the same until temp reaches to 'rear' (temp → next != NULL).
 Step 5: Display temp → data ---> NULL.
Application of Linked List
 Various application of linked list are :
1. Representation of polynomial and performing various operations
such as addition, multiplication and evaluation on it.
2. Performing addition of long positive integers.
3. Representing non integer and non homogeneous list.
Linked list

More Related Content

What's hot

Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
Akila Krishnamoorthy
 
Linked list
Linked list Linked list
Linked list
Arbind Mandal
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
KristinaBorooah
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
DurgaDeviCbit
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
Dr. Sindhia Lingaswamy
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
Elavarasi K
 
Insertion in singly linked list
Insertion in singly linked listInsertion in singly linked list
Insertion in singly linked list
Keval Bhogayata
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
Hossain Md Shakhawat
 
Linked lists
Linked listsLinked lists
Linked lists
SARITHA REDDY
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queueSenthil Kumar
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
DivyeshKumar Jagatiya
 
linked list
linked listlinked list
linked list
Shaista Qadir
 
Linkedlist
LinkedlistLinkedlist
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ManishPrajapati78
 

What's hot (20)

Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
single linked list
single linked listsingle linked list
single linked list
 
Linked list
Linked list Linked list
Linked list
 
Stack
StackStack
Stack
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
 
Insertion in singly linked list
Insertion in singly linked listInsertion in singly linked list
Insertion in singly linked list
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Linked list
Linked listLinked list
Linked list
 
Linked lists
Linked listsLinked lists
Linked lists
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Linked List
Linked ListLinked List
Linked List
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
linked list
linked listlinked list
linked list
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 

Similar to Linked list

queue
queuequeue
queue
umair khan
 
Circular linked list
Circular linked list Circular linked list
Circular linked list
sajinis3
 
lab stack and queue.docx
lab stack and queue.docxlab stack and queue.docx
lab stack and queue.docx
R S Anu Prabha
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
Muhazzab Chouhadry
 
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssssDSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
beshahashenafe20
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
ssuser7319f8
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
MeghaKulkarni27
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
Dabbal Singh Mahara
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked listAmit Vats
 
Dounly linked list
Dounly linked listDounly linked list
Dounly linked list
NirmalPandey23
 
VCE Unit 02 (1).pptx
VCE Unit 02 (1).pptxVCE Unit 02 (1).pptx
VCE Unit 02 (1).pptx
skilljiolms
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
EktaVaswani2
 
DSModule2.pptx
DSModule2.pptxDSModule2.pptx
DSModule2.pptx
ChrisSosaJacob
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
Afaq Mansoor Khan
 
DSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUEDSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUE
swathirajstar
 
Linked list implementation of Stack
Linked list implementation of StackLinked list implementation of Stack
Linked list implementation of Stack
Dr. Sindhia Lingaswamy
 
Singlelinked list
Singlelinked listSinglelinked list
Singlelinked list
Lakshmi Sarvani Videla
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
Programming Exam Help
 

Similar to Linked list (20)

queue
queuequeue
queue
 
Circular linked list
Circular linked list Circular linked list
Circular linked list
 
lab stack and queue.docx
lab stack and queue.docxlab stack and queue.docx
lab stack and queue.docx
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
 
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssssDSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked list
 
Dounly linked list
Dounly linked listDounly linked list
Dounly linked list
 
VCE Unit 02 (1).pptx
VCE Unit 02 (1).pptxVCE Unit 02 (1).pptx
VCE Unit 02 (1).pptx
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
DSModule2.pptx
DSModule2.pptxDSModule2.pptx
DSModule2.pptx
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
DSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUEDSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUE
 
1. 3 singly linked list insertion 2
1. 3 singly linked list   insertion 21. 3 singly linked list   insertion 2
1. 3 singly linked list insertion 2
 
Linked list implementation of Stack
Linked list implementation of StackLinked list implementation of Stack
Linked list implementation of Stack
 
Singlelinked list
Singlelinked listSinglelinked list
Singlelinked list
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 

Recently uploaded

Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 

Recently uploaded (20)

Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 

Linked list

  • 2. VARIOUS TYPES OF LINKED LIST able of Contents  Circular Linked List  Linked Implementation of Stack  Linked Implementation of Queue Application of Linked List
  • 3. Concept of Linked List  Linked list is a linear data structure.  A Linked List is a set of nodes where each node has two fields ‘data’ and ‘link’. DATA LINK  Piece of Information Data Type : Int,char,float etc. Used to point to next node
  • 4. C Representation of Simple Linked List  C structure for creating a node in a Linked List : typedef struct node { int data; struct node *next; }NODE; Stores Information part of data Stores address of next node
  • 5. Circular Linked List  Circular linked list is a sequence of elements in which every element has link to its next element in the sequence and the last element has the link to the first element in the sequence.  The circular linked list is as shown below : 10 20 30 40 50 Head Node
  • 6. Operation performed on Circular Linked List  The following operation can be performed on Circular linked list. 1. Insertion 2. Deletion 3. Display
  • 7. Insertion of Circular Linked list  Algorithm: Step 1: Create a new_node with a given value. Step 2: Check whether list is empty (head==NULL). Step 3: If empty, then head=new_node and new_node→next=head. Step 4: If not empty then create a temp node pointer and initialize with ‘head’. Step 5: Move temp node to its next node, until head node not achieved (temp→next==head). Step 6: Set new_node→next=head, head=new_node and temp→next=head. Inserting a node as a head node
  • 8.  Algorithm: Step 1: Create a new_node with a given value. Step 2: Check whether list is empty (head==NULL). Step 3: If empty, then head=new_node and new_node→next=head. Step 4: If not empty then create a temp node pointer and initialize with ‘head’. Step 5: Move temp node to its next node, until head node not achieved (temp->next==head). Step 6: Set temp→next=new_node and new_node→next=head. Inserting a node as a last node
  • 9.  Algorithm: Step 1: Create a new_node with a given value. Step 2: Check whether list is empty (head==NULL). Step 3: If empty, then head=new_node and new_node->next=head. Step 4: If not empty then create a temp node pointer and initialize with ‘head’. Step 5: Define key value after which the node is to be inserted. Step 6: Check for key value (temp→data==key). Step 7: Every time check whether temp is reached to the last node or not. If yes then print Node not found. Step 8: If temp=key then check whether it is last node (temp→next==head). Step 9: If temp is last node then temp->next=new_node and new_node→next=head. Step 10: If temp is not last node then new_node→next=temp→next and temp→next=new_node. Inserting a node at specific location
  • 10. Deletion of any node  Algorithm: Step 1: Check whether list is Empty (head == NULL). Step 2: If it is Empty then, print list is empty. Step 3: If it is Not Empty then, define two Node pointers 'temp1' and 'temp2' and initialize 'temp1' with head. Step 4: Keep moving the temp1 until it reaches to the specified or to the last node. And every time set 'temp2 = temp1' before moving the 'temp1' to its next node. Step 5: If it is reached to the last node then display Node not found. Step 6: If it is reached to the exact node which we want to delete, then check whether list is having only one node (temp1→next == head).
  • 11. Step 7: If list has only one node and that is the node to be deleted then set head=NULL and delete temp1 (free(temp1)). Step 8: If list contains multiple nodes then check whether temp1 is the first node in the list (temp1 == head). Step 9: If temp1 is the first node then set temp2 = head and keep moving temp2 to its next node until temp2 reaches to the last node. Then set head=head→next, temp2→next=head and delete temp1. Step 10: If temp1 is not first node then check whether it is last node in the list (temp1→next == head). Step 11: If temp1 is last node then set temp2→next=head and delete temp1 (free(temp1)). Step 12: If temp1 is not first node and not last node then set temp2→next = temp1→next and delete temp1 (free(temp1)).
  • 12. Display Circular Linked List  Algorithm: Step 1: Check whether list is Empty (head == NULL). Step 2: If it is Empty, then print list is empty. Step 3: If it is Not Empty then, define a Node pointer 'temp' and initialize with head. Step 4: Keep displaying temp→data with an arrow (--->) until temp reaches to the last node. Step 5: Finally display temp→data with arrow pointing to head→data.
  • 13. Advantages of Circular Linked list over Singly Linked list  In Circular linked list, the next pointer of last node in pointing to the head node.  Hence we can move from last node to the head node of the list very efficiently.  So, accessing of any node is much faster then singly linked list.  The last node’s next pointer have null value in singly linked list while in circular linked list it is having the address of the head node.  Hence there is no loss of memory.
  • 14. Linked Implementation of Stack  Stack is a special case of list and therefore we can represent stack using arrays as well as using linked list.  The advantage of implementing stack using linked list is that we need not have to worry about the size of the stack.  Since we are using linked list as stack, we are inserting the nodes in the stack and the size is dynamically changed. So there is not stack full (Overflow condition).
  • 15. C structure of Linked Stack Representation of Linked Stack struct stack { int data; struct stack *next; }NODE; 40 30 20 10 NULL Top Node
  • 16. Insert a node into Linked Stack  We can insert the node using user defined function named push(value).  Algorithm:  Step 1: Create a new_node with given value.  Step 2: Check whether stack is Empty (top == NULL).  Step 3: If it is Empty, then set new_node→next=NULL.  Step 4: If it is Not Empty, then set new_node→next=top.  Step 5: set top = new_node.
  • 17. Delete a node from Linked Stack  We can delete a node from linked stack using user defined function called pop().  Algorithm:  Step 1: Check whether stack is Empty (top == NULL).  Step 2: If it is Empty, then display “Stack is empty”.  Step 3: If it is Not Empty, then define a Node pointer 'temp' and set it to 'top'.  Step 4: Then set 'top = top → next'.  Step 5: Delete 'temp' (free(temp)).
  • 18. Display Linked Stack  Algorithm:  Step 1: Check whether stack is Empty (top == NULL).  Step 2: If it is Empty, then display “Stack is Empty”.  Step 3: If it is Not Empty, then define a Node pointer 'temp' and initialize with top.  Step 4: Display 'temp → data --->' and move it to the next node. Repeat the same until temp reaches to the first node in the stack (temp → next != NULL).  Step 5: Display 'temp → data ---> NULL'.
  • 19. Linked Implementation of Queue  We can implement queue using linked list.  The main advantage is we need not have to worry about size of the queue, so there will not be a queue full condition.  The left most pointer is called front node and the right most pointer is called rear node.  We can not remove any arbitrary node from queue.
  • 20. C structure of Linked Queue Representation of Linked Queue struct node { int data; struct stack *next; }Q; 40302010 Front node Rear node
  • 21. Insert a node into Linked Queue  Algorithm:  Step 1: Create a new_node and set new_node → next = NULL.  Step 2: Check whether queue is Empty (rear == NULL)  Step 3: If it is Empty then, set front = new_node and rear = new_node.  Step 4: If it is Not Empty then, set rear→next = new_node and rear = new_node.
  • 22. Delete a node from Linked Queue  Algorithm:  Step 1: Check whether queue is Empty (front == NULL).  Step 2: If it is Empty, then display "Queue is Empty!!!”  Step 3: If it is Not Empty then, define a Node pointer temp and set it to front.  Step 4: Then 'front = front → next' and delete 'temp' (free(temp)).
  • 23. Display Linked Queue  Algorithm:  Step 1: Check whether queue is Empty (front == NULL).  Step 2: If it is Empty then, display “Queue is Empty!!!”  Step 3: If it is Not Empty then, define a Node pointer temp and initialize with front.  Step 4: Display temp → data ---> and move it to the next node. Repeat the same until temp reaches to 'rear' (temp → next != NULL).  Step 5: Display temp → data ---> NULL.
  • 24. Application of Linked List  Various application of linked list are : 1. Representation of polynomial and performing various operations such as addition, multiplication and evaluation on it. 2. Performing addition of long positive integers. 3. Representing non integer and non homogeneous list.