SlideShare a Scribd company logo
1 of 18
LINKED LISTS
Prepared by:
Muhammad Zohaib Azad
Hajra Israr
Ayesha Sajjad
What are linked lists?
A Linked Lists is a linear data structure.
Nodes make up linked lists.
Nodes are structures made up of data and a
pointer to another node.
Usually the pointer is called next.
5 * 6 * 7 * 8*
Null
head
Real Life Example:
A linked list is like scavenger hunt. You have a clue, and that
clue has a pointer to the next place having the next clue. So
you go to the next place and get another piece of data and
another pointer. To get something in the middle or at the end,
the only way is to follow the list from beginning.
Types of lists:
There are two types of lists:
1. Singly linked lists 2. Doubly linked lists
5 * 6*
Head
Node
NULLSingly list
5 * 6
Doubly list
5 *
Head
* *
NULL
prev
next
prev prev
next next
NULL
Basic Operation on a list
• Creating a list
• Inserting an element in a list
• Deleting an element in a list
• Searching a list
• Reversing a list
Creating a node
Struct node{
int data; //A simple node of a linked list
node*next;
}*start //Start points at the first node
Start =NULL; initialized to NULL at beginning
Node*create(int num) //say num=1 is passed from main
Node*ptr;
Ptr = new node; //memory located dynamically
if (ptr==NULL)
“OVERFLOW” //no memory available
exit(1);
Else {
ptr->data= num;
ptr->next=NULL;
return ptr;
}
Main function is:
void main()
{
node*ptr;
int data;
cin>>data;
ptr=create(data);
}
Inserting the nod in singly
linked list:
There are 3 cases here:
1. Insertion at the beginning
2. Insertion at the end
3. Insertion at the particular node
Insertion at the beginning:
There are two steps to be followed:
1. Make the next pointer of the node point towards the first node of the list.
2. Make the start pointer point towards this new node
If the list is empty simply make the start pointer point towards the new node;
5
65 5
Head
New
node
void insert_beg(node* p)
{ node* temp;
if(start==NULL) //if the list is empty
{
start=p;
cout<<”nNode inserted successfully at the beginning”;
}
else {
temp=start;
start=p;
p->next=temp; //making new node point at
} the first node of the list
}
Insertion at the end:
Here we simply need to make the next pointer of the last
node point to the new node
96 100 102
prev New
node
Formerly null
void insert_end(node* p)
{
node *q=start;
if(start==NULL)
{
start=p;
cout<<”nNode inserted successfully at the end…!!!n”;
}
else{
while(q->link!=NULL)
q=q->link;
q->next=p;
}
}
Inserting after an element:
Here we again need to do 2 steps :-
1. 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
2. Make the next pointer of the node after which the node is
to be inserted, point to the node to be inserted
96 100 102
96
New node
void insert_after(int c,node* p)
{
node* q;
q=start;
for(int i=1;i<c;i++)
{
q=q->link;
if(q==NULL)
cout<<”Less than “<<c<<” nodes in the list…!!!”;
}
p->link=q->link;
q->link=p;
cout<<”nNode inserted successfully”;
}
linked list

More Related Content

What's hot

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
 
Circular linked list
Circular linked listCircular linked list
Circular linked listmaamir farooq
 
Linked list
Linked listLinked list
Linked listVONI
 
Data Structure Lecture 5
Data Structure Lecture 5Data Structure Lecture 5
Data Structure Lecture 5Teksify
 
linked list using c
linked list using clinked list using c
linked list using cVenkat Reddy
 
Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)shah alom
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked listSumathi Kv
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data StructureMuhazzab Chouhadry
 
Insertion into linked lists
Insertion into linked lists Insertion into linked lists
Insertion into linked lists MrDavinderSingh
 

What's hot (20)

Linked List
Linked ListLinked List
Linked List
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
 
Linked list
Linked listLinked list
Linked list
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
Linked lists 1
Linked lists 1Linked lists 1
Linked lists 1
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Linked list
Linked listLinked list
Linked list
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
Linklist
LinklistLinklist
Linklist
 
Data Structure (Double Linked List)
Data Structure (Double Linked List)Data Structure (Double Linked List)
Data Structure (Double Linked List)
 
Data Structure Lecture 5
Data Structure Lecture 5Data Structure Lecture 5
Data Structure Lecture 5
 
linked list
linked list linked list
linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
linked list using c
linked list using clinked list using c
linked list using c
 
Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
Link List
Link ListLink List
Link List
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
 
Insertion into linked lists
Insertion into linked lists Insertion into linked lists
Insertion into linked lists
 

Similar to linked list

data structures lists operation of lists
data structures lists operation of listsdata structures lists operation of lists
data structures lists operation of listsmuskans14
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversalkasthurimukila
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxMeghaKulkarni27
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfKylaMaeGarcia1
 
DS_LinkedList.pptx
DS_LinkedList.pptxDS_LinkedList.pptx
DS_LinkedList.pptxmsohail37
 
Linked List in Data Structure
Linked List in Data StructureLinked List in Data Structure
Linked List in Data StructureMeghaj Mallick
 
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssssDSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssssbeshahashenafe20
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked listAmit Vats
 

Similar to linked list (20)

Linked list
Linked list Linked list
Linked list
 
data structures lists operation of lists
data structures lists operation of listsdata structures lists operation of lists
data structures lists operation of lists
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversal
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
linked-list.ppt
linked-list.pptlinked-list.ppt
linked-list.ppt
 
Linked list
Linked listLinked list
Linked list
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
 
Lec3-Linked list.pptx
Lec3-Linked list.pptxLec3-Linked list.pptx
Lec3-Linked list.pptx
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 
DS_LinkedList.pptx
DS_LinkedList.pptxDS_LinkedList.pptx
DS_LinkedList.pptx
 
linkrd_list.pdf
linkrd_list.pdflinkrd_list.pdf
linkrd_list.pdf
 
Linked List in Data Structure
Linked List in Data StructureLinked List in Data Structure
Linked List in Data Structure
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
 
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssssDSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked list
 
Linked list.docx
Linked list.docxLinked list.docx
Linked list.docx
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 

Recently uploaded

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 

Recently uploaded (20)

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

linked list

  • 1.
  • 2. LINKED LISTS Prepared by: Muhammad Zohaib Azad Hajra Israr Ayesha Sajjad
  • 3. What are linked lists? A Linked Lists is a linear data structure. Nodes make up linked lists. Nodes are structures made up of data and a pointer to another node. Usually the pointer is called next. 5 * 6 * 7 * 8* Null head
  • 4. Real Life Example: A linked list is like scavenger hunt. You have a clue, and that clue has a pointer to the next place having the next clue. So you go to the next place and get another piece of data and another pointer. To get something in the middle or at the end, the only way is to follow the list from beginning.
  • 5. Types of lists: There are two types of lists: 1. Singly linked lists 2. Doubly linked lists 5 * 6* Head Node NULLSingly list 5 * 6 Doubly list 5 * Head * * NULL prev next prev prev next next NULL
  • 6. Basic Operation on a list • Creating a list • Inserting an element in a list • Deleting an element in a list • Searching a list • Reversing a list
  • 7. Creating a node Struct node{ int data; //A simple node of a linked list node*next; }*start //Start points at the first node Start =NULL; initialized to NULL at beginning
  • 8. Node*create(int num) //say num=1 is passed from main Node*ptr; Ptr = new node; //memory located dynamically if (ptr==NULL) “OVERFLOW” //no memory available exit(1); Else { ptr->data= num; ptr->next=NULL; return ptr; }
  • 9. Main function is: void main() { node*ptr; int data; cin>>data; ptr=create(data); }
  • 10. Inserting the nod in singly linked list: There are 3 cases here: 1. Insertion at the beginning 2. Insertion at the end 3. Insertion at the particular node
  • 11. Insertion at the beginning: There are two steps to be followed: 1. Make the next pointer of the node point towards the first node of the list. 2. Make the start pointer point towards this new node If the list is empty simply make the start pointer point towards the new node; 5 65 5 Head New node
  • 12. void insert_beg(node* p) { node* temp; if(start==NULL) //if the list is empty { start=p; cout<<”nNode inserted successfully at the beginning”; } else { temp=start; start=p; p->next=temp; //making new node point at } the first node of the list }
  • 13. Insertion at the end: Here we simply need to make the next pointer of the last node point to the new node 96 100 102 prev New node Formerly null
  • 14. void insert_end(node* p) { node *q=start; if(start==NULL) { start=p; cout<<”nNode inserted successfully at the end…!!!n”; } else{ while(q->link!=NULL) q=q->link; q->next=p; } }
  • 15. Inserting after an element: Here we again need to do 2 steps :- 1. 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 2. Make the next pointer of the node after which the node is to be inserted, point to the node to be inserted
  • 17. void insert_after(int c,node* p) { node* q; q=start; for(int i=1;i<c;i++) { q=q->link; if(q==NULL) cout<<”Less than “<<c<<” nodes in the list…!!!”; } p->link=q->link; q->link=p; cout<<”nNode inserted successfully”; }