SlideShare une entreprise Scribd logo
1  sur  18
Deletion from single way
linked list and search
PRESENTED BY:
M D I S L A M K H A N 171-15-9537
A B D U L L A H A L R E D WA N 171-15-9538
A S I Q U R R A H M A N A S I Q 171-15-9528
M O M I N U R I S L A M A S A D 163-15-8523
Linked list
linked list is a linear data structure. It contains
nodes. Each node contains two parts,
i.e. DATA part and LINK part.
 The data contains elements , and
 Link contains address of another node.
WHAT ARE LINKED LISTS
A linked list 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.
TYPES OF LINKED LISTS
1. Single linked list.
2. Double linked list.
3. Circular linked list.
4. Circular double linked list.
Singly Linked List
 Each node has only one link part.
Each link part contains the address of the next node in
the list.
Link part of the last node contains NULL value which
signifies the end of the node.
BASIC OPERATIONS ON A LIST
 Creating a List
 Inserting an element in a list
 Deleting an element from a list
 Searching a list
 Reversing a list
Deleting a Node in SLL
Here also we have three cases:-
Deleting the first node
Deleting the last node
Deleting the intermediate node
DELETING THE FIRST NODE
Here we apply 2 steps:-
 Making the start pointer point towards the 2nd node.
Deleting the first node using delete keyword.
void delete_from_first()
{
struct node* temp=head;
head=head->next/temp->next;
free(temp);
}
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.
void delete_from_last()
{
struct node *temp=head, *temp2;
while(temp->next)
{
temp2=temp;
temp=temp->next;
}
temp2->next=NULL;
free(temp);
}
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.
void delete_from_any_position(int pos)
{
int i ;
struct node *temp=head, *temp2;
for(i=2 ; i<pos ; i++)
{
temp=temp->next;
}
temp2=temp->next
temp->next=temp2->next;
free(temp2);
}
Searching a SLL
 Searching involves finding the required element in the list.
 We can use various techniques of searching like linear search or
binary search where binary search is more efficient in case of
Arrays.
 But in case of linked list since random access is not available it
would become complex to do binary search in it.
 We can perform simple linear search traversal.
 In linear search each node is traversed till the data in
the node matches with the required value:
void search (int x)
{
node*temp=start;
while(temp!=NULL)
{
if(temp->data==x)
{
cout<<“FOUND ”<<temp->data;
break;
}
temp=temp->next;
}
APPLICATIONS OF LINKED LIST
A linked list is a very efficient data structure for sorted list
that will go through many insertions and deletions.
A linked list is a dynamic data structure in which the list
can start with no nodes and then grow as new nodes are
needed. A node can be easily deleted without moving other
nodes, as would be the case with an array.
For example, a linked list could be used to hold the records
of students in a school. Each quarter or semester , new
students enroll in the school and some students leave or
graduate.
 Advantages of using a Linked list:
Save space (don’t have to worry about sparse polynomials) and
easy to maintain.
 Don’t need to allocate list size and can declare nodes (terms) only
as needed.
Operation related to data elements like insertions or deletion are
more simplified
 Disadvantages of using a Linked list :
 Can’t go backwards through the list.
 Can’t jump to the beginning of the list from the end.
Deletion from single way linked list and search

Contenu connexe

Tendances

Tendances (20)

Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
Sparse matrix and its representation data structure
Sparse matrix and its representation data structureSparse matrix and its representation data structure
Sparse matrix and its representation data structure
 
Singly link list
Singly link listSingly link list
Singly link list
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
 
Heap sort
Heap sortHeap sort
Heap sort
 
Linked lists
Linked listsLinked lists
Linked lists
 
Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
Red black tree
Red black treeRed black tree
Red black tree
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
 
Array in c language
Array in c languageArray in c language
Array in c language
 
DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS DATA STRUCTURE AND ALGORITHMS
DATA STRUCTURE AND ALGORITHMS
 
2D Array
2D Array2D Array
2D Array
 
Linked List
Linked ListLinked List
Linked List
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 

Similaire à Deletion from single way linked list and search

linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
ds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfKamranAli649587
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptxssuserd2f031
 
Linked List in Data Structure
Linked List in Data StructureLinked List in Data Structure
Linked List in Data StructureMeghaj Mallick
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked listSumathi Kv
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1DrSudeshna
 
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 list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversalkasthurimukila
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfKylaMaeGarcia1
 
DS Module 03.pdf
DS Module 03.pdfDS Module 03.pdf
DS Module 03.pdfSonaPathak5
 
Data Structures_Linked List
Data Structures_Linked ListData Structures_Linked List
Data Structures_Linked ListThenmozhiK5
 

Similaire à Deletion from single way linked list and search (20)

linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Linked list (1).pptx
Linked list (1).pptxLinked list (1).pptx
Linked list (1).pptx
 
ds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdf
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
 
csc211_lecture_21.pptx
csc211_lecture_21.pptxcsc211_lecture_21.pptx
csc211_lecture_21.pptx
 
Linked list.docx
Linked list.docxLinked list.docx
Linked list.docx
 
Linked List in Data Structure
Linked List in Data StructureLinked List in Data Structure
Linked List in Data Structure
 
Unit II Data Structure 2hr topic - List - Operations.pptx
Unit II  Data Structure 2hr topic - List - Operations.pptxUnit II  Data Structure 2hr topic - List - Operations.pptx
Unit II Data Structure 2hr topic - List - Operations.pptx
 
Linked List
Linked ListLinked List
Linked List
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
 
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 list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversal
 
Linkedlists
LinkedlistsLinkedlists
Linkedlists
 
Link list assi
Link list assiLink list assi
Link list assi
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
 
Linked list
Linked listLinked list
Linked list
 
DS Module 03.pdf
DS Module 03.pdfDS Module 03.pdf
DS Module 03.pdf
 
Data Structures_Linked List
Data Structures_Linked ListData Structures_Linked List
Data Structures_Linked List
 

Plus de Estiak Khan

Steps in simulation study
Steps in simulation studySteps in simulation study
Steps in simulation studyEstiak Khan
 
Smart bajarlist wireless
Smart bajarlist wirelessSmart bajarlist wireless
Smart bajarlist wirelessEstiak Khan
 
Scrum agile-process
Scrum agile-processScrum agile-process
Scrum agile-processEstiak Khan
 
Graphical user-interface
Graphical user-interfaceGraphical user-interface
Graphical user-interfaceEstiak Khan
 
Graphical User Interface (GUI)
Graphical User Interface (GUI)Graphical User Interface (GUI)
Graphical User Interface (GUI)Estiak Khan
 
Graphical user-interface (GUI)
Graphical user-interface (GUI)Graphical user-interface (GUI)
Graphical user-interface (GUI)Estiak Khan
 
Future operating system
Future operating systemFuture operating system
Future operating systemEstiak Khan
 
Android operating system
Android operating systemAndroid operating system
Android operating systemEstiak Khan
 
Disadvantages of cloud computing
Disadvantages of cloud computingDisadvantages of cloud computing
Disadvantages of cloud computingEstiak Khan
 
Determinants of supply
Determinants of supplyDeterminants of supply
Determinants of supplyEstiak Khan
 
Distributed systems-analysis-and-design
Distributed systems-analysis-and-designDistributed systems-analysis-and-design
Distributed systems-analysis-and-designEstiak Khan
 
wireless networking
wireless networkingwireless networking
wireless networkingEstiak Khan
 
Online Banking System
Online Banking SystemOnline Banking System
Online Banking SystemEstiak Khan
 

Plus de Estiak Khan (20)

Decision tree
Decision treeDecision tree
Decision tree
 
Steps in simulation study
Steps in simulation studySteps in simulation study
Steps in simulation study
 
Smart bajarlist wireless
Smart bajarlist wirelessSmart bajarlist wireless
Smart bajarlist wireless
 
Spiral model
Spiral modelSpiral model
Spiral model
 
Scrum agile-process
Scrum agile-processScrum agile-process
Scrum agile-process
 
Waterfall model
Waterfall modelWaterfall model
Waterfall model
 
V model
V modelV model
V model
 
Use case-slide
Use case-slideUse case-slide
Use case-slide
 
Graphical user-interface
Graphical user-interfaceGraphical user-interface
Graphical user-interface
 
Graphical User Interface (GUI)
Graphical User Interface (GUI)Graphical User Interface (GUI)
Graphical User Interface (GUI)
 
Graphical user-interface (GUI)
Graphical user-interface (GUI)Graphical user-interface (GUI)
Graphical user-interface (GUI)
 
Future operating system
Future operating systemFuture operating system
Future operating system
 
Android operating system
Android operating systemAndroid operating system
Android operating system
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
Disadvantages of cloud computing
Disadvantages of cloud computingDisadvantages of cloud computing
Disadvantages of cloud computing
 
Determinants of supply
Determinants of supplyDeterminants of supply
Determinants of supply
 
Law of supply
Law of supplyLaw of supply
Law of supply
 
Distributed systems-analysis-and-design
Distributed systems-analysis-and-designDistributed systems-analysis-and-design
Distributed systems-analysis-and-design
 
wireless networking
wireless networkingwireless networking
wireless networking
 
Online Banking System
Online Banking SystemOnline Banking System
Online Banking System
 

Dernier

ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 

Dernier (20)

ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 

Deletion from single way linked list and search

  • 1. Deletion from single way linked list and search PRESENTED BY: M D I S L A M K H A N 171-15-9537 A B D U L L A H A L R E D WA N 171-15-9538 A S I Q U R R A H M A N A S I Q 171-15-9528 M O M I N U R I S L A M A S A D 163-15-8523
  • 2. Linked list linked list is a linear data structure. It contains nodes. Each node contains two parts, i.e. DATA part and LINK part.  The data contains elements , and  Link contains address of another node.
  • 3. WHAT ARE LINKED LISTS A linked list 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.
  • 4. TYPES OF LINKED LISTS 1. Single linked list. 2. Double linked list. 3. Circular linked list. 4. Circular double linked list.
  • 5. Singly Linked List  Each node has only one link part. Each link part contains the address of the next node in the list. Link part of the last node contains NULL value which signifies the end of the node.
  • 6. BASIC OPERATIONS ON A LIST  Creating a List  Inserting an element in a list  Deleting an element from a list  Searching a list  Reversing a list
  • 7. Deleting a Node in SLL Here also we have three cases:- Deleting the first node Deleting the last node Deleting the intermediate node
  • 8. DELETING THE FIRST NODE Here we apply 2 steps:-  Making the start pointer point towards the 2nd node. Deleting the first node using delete keyword.
  • 9. void delete_from_first() { struct node* temp=head; head=head->next/temp->next; free(temp); }
  • 10. 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.
  • 11. void delete_from_last() { struct node *temp=head, *temp2; while(temp->next) { temp2=temp; temp=temp->next; } temp2->next=NULL; free(temp); }
  • 12. 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.
  • 13. void delete_from_any_position(int pos) { int i ; struct node *temp=head, *temp2; for(i=2 ; i<pos ; i++) { temp=temp->next; } temp2=temp->next temp->next=temp2->next; free(temp2); }
  • 14. Searching a SLL  Searching involves finding the required element in the list.  We can use various techniques of searching like linear search or binary search where binary search is more efficient in case of Arrays.  But in case of linked list since random access is not available it would become complex to do binary search in it.  We can perform simple linear search traversal.
  • 15.  In linear search each node is traversed till the data in the node matches with the required value: void search (int x) { node*temp=start; while(temp!=NULL) { if(temp->data==x) { cout<<“FOUND ”<<temp->data; break; } temp=temp->next; }
  • 16. APPLICATIONS OF LINKED LIST A linked list is a very efficient data structure for sorted list that will go through many insertions and deletions. A linked list is a dynamic data structure in which the list can start with no nodes and then grow as new nodes are needed. A node can be easily deleted without moving other nodes, as would be the case with an array. For example, a linked list could be used to hold the records of students in a school. Each quarter or semester , new students enroll in the school and some students leave or graduate.
  • 17.  Advantages of using a Linked list: Save space (don’t have to worry about sparse polynomials) and easy to maintain.  Don’t need to allocate list size and can declare nodes (terms) only as needed. Operation related to data elements like insertions or deletion are more simplified  Disadvantages of using a Linked list :  Can’t go backwards through the list.  Can’t jump to the beginning of the list from the end.