SlideShare uma empresa Scribd logo
1 de 58
[object Object],[object Object],[object Object],Linked List 10 20 30 10 NULL Node A Node B Node C Node D P
[object Object],[object Object],[object Object],Node DATA POINTER 10 NODE
Declarations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Structure
ADD ,[object Object],[object Object],[object Object],[object Object],[object Object]
If list is empty i.e. P==NULL ,[object Object],[object Object],P Q NULL
If list is empty i.e. P==NULL P Q NULL
If list is empty i.e. P==NULL P Q p=(struct node *) malloc(sizeof(struct node))
If list is empty i.e. P==NULL P Q p=(struct node *) malloc(sizeof(struct node)) P->data=num 10
If list is empty i.e. P==NULL P Q p=(struct node *) malloc(sizeof(struct node)) P->data=num 10 P->link=NULL NULL
If list is not empty i.e. p!=NULL 10 20 30 Node A Node B Node C NULL P Q
If list is not empty i.e. p!=NULL 10 20 30 Node A Node B Node C NULL P Q ,[object Object],[object Object],true
If list is not empty i.e. p!=NULL 10 20 30 Node A Node B Node C NULL P Q ,[object Object],[object Object],false
If list is not empty i.e. p!=NULL 10 20 30 Node A Node B Node C P Q ,[object Object],[object Object],[object Object],[object Object],10 Node D NULL
DISPLAY ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
If list is empty P Q NULL ,[object Object],[object Object],[object Object],[object Object]
If list is not empty i.e. p!=NULL 10 20 30 Node A Node B Node C NULL P Q ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],true o/p : 10 o/p : 20
If list is not empty i.e. p!=NULL 10 20 30 Node A Node B Node C NULL P Q ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],o/p : 10 o/p : 20 o/p : 30
If list is not empty i.e. p!=NULL 10 20 30 Node A Node B NULL Node C P Q ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],false o/p : 10 o/p : 20 o/p : 30
INSERT ,[object Object],[object Object]
If position is 1 10 20 30 Node A Node B Node C NULL Q P
If position is 1 10 20 30 Node A Node B Node C NULL Q P p=(struct node *) malloc(sizeof(struct node));
If position is 1 10 20 30 Node A Node B Node C NULL Q P p=(struct node *) malloc(sizeof(struct node)); p->data=num 5
If position is 1 10 20 30 Node A Node B Node C NULL Q P p=(struct node *) malloc(sizeof(struct node)); p->data=num; 5 p->link=q;
If position is greater than 1 10 20 30 Node A Node B Node C NULL Q P Suppose a node is to be inserted at position 3.
10 20 30 Node A Node B Node C NULL P Q for(i=1;i<=3-2;i++) { q=q->link; }
10 20 30 Node A Node B Node C NULL P Q for(i=1;i<=3-2;i++) { q=q->link; } temp
10 20 30 Node A Node B Node C NULL P Q for(i=1;i<=3-2;i++) { q=q->link; } temp
10 20 30 Node A Node B Node C NULL P Q for(i=1;i<=3-2;i++) { q=q->link; } temp Node BC q->link=(struct node *) malloc(sizeof(struct node));
10 20 30 Node A Node B Node C NULL P Q for(i=1;i<=3-2;i++) { q=q->link; } temp Node BC q->link=(struct node *) malloc(sizeof(struct node)); 25 q->link->data=num;
10 20 30 Node A Node B Node C NULL P Q for(i=1;i<=3-2;i++) { q=q->link; } temp Node BC q->link=(struct node *) malloc(sizeof(struct node)); 25 q->link->data=num; q->link->link=temp;
COUNT ,[object Object],[object Object],[object Object]
If list is not empty i.e. p!=NULL 10 20 30 Node A Node B Node C NULL P Q ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],true counter= 1 counter=2
If list is not empty i.e. p!=NULL 10 20 30 Node A Node B Node C NULL P Q ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],counter=1 counter=2 counter=3
If list is not empty i.e. p!=NULL 10 20 30 Node A Node B NULL Node C P Q ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],false counter=3 counter=1 counter=2
REVERSE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SEARCH ,[object Object],[object Object],[object Object],[object Object]
SEARCH ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],10 20 30 Node A Node B Node C P Q 40 NULL Node D position=1 position=2 position=3 position=4
SEARCH ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],10 20 30 Node A Node B Node C P Q 40 NULL Node D true position=1 position=2 position=3 position=4
REMOVE ,[object Object],[object Object]
If position is 1 10 20 30 10 NULL Node A Node B Node C Node D P Q
If position is 1 10 20 30 10 NULL Node A Node B Node C Node D P Q ,[object Object]
If position is 1 10 20 30 10 NULL Node A Node B Node C Node D P Q
If position is 1 20 30 10 NULL Node B Node C Node D P Q ,[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],10 20 30 Node A Node B Node C P Q 40 NULL Node D
[object Object],[object Object],[object Object],[object Object],[object Object],10 20 30 Node A Node B Node C P Q 40 NULL Node D
[object Object],[object Object],[object Object],[object Object],[object Object],10 20 30 Node A Node B Node C P Q 40 NULL Node D q->link=q->link->link;
SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link)   {   if(i->data>j->data)   {   temp=i->data;   i->data=j->data;   j->data=temp;   }   } } 7 6 3 Node A Node B Node C 1 NULL Node D i j
SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link)   {   if(i->data>j->data)   {   temp=i->data;   i->data=j->data;   j->data=temp;   }   } } 7 6 3 Node A Node B Node C 1 NULL Node D i j
SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link)   {   if(i->data>j->data)   {   temp=i->data;   i->data=j->data;   j->data=temp;   }   } } 6 7 3 Node A Node B Node C 1 NULL Node D i j
SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link)   {   if(i->data>j->data)   {   temp=i->data;   i->data=j->data;   j->data=temp;   }   } } 3 7 6 Node A Node B Node C 1 NULL Node D i j
SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link)   {   if(i->data>j->data)   {   temp=i->data;   i->data=j->data;   j->data=temp;   }   } } 3 7 6 Node A Node B Node C 1 NULL Node D i j
SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link)   {   if(i->data>j->data)   {   temp=i->data;   i->data=j->data;   j->data=temp;   }   } } 1 7 6 Node A Node B Node C 3 NULL Node D i j
SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link)   {   if(i->data>j->data)   {   temp=i->data;   i->data=j->data;   j->data=temp;   }   } } 1 6 7 Node A Node B Node C 3 NULL Node D i j
SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link)   {   if(i->data>j->data)   {   temp=i->data;   i->data=j->data;   j->data=temp;   }   } } 1 3 7 Node A Node B Node C 6 NULL Node D i j
SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link)   {   if(i->data>j->data)   {   temp=i->data;   i->data=j->data;   j->data=temp;   }   } } 1 3 7 Node A Node B Node C 6 NULL Node D i j
SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link)   {   if(i->data>j->data)   {   temp=i->data;   i->data=j->data;   j->data=temp;   }   } } 1 3 6 Node A Node B Node C 7 NULL Node D i j
Presented by ,[object Object]

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Singly link list
Singly link listSingly link list
Singly link list
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
linked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutoriallinked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutorial
 
Linked list
Linked listLinked list
Linked list
 
Red black tree
Red black treeRed black tree
Red black tree
 
Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptx
 
Linked list
Linked listLinked list
Linked list
 
Array operations
Array operationsArray operations
Array operations
 
stack presentation
stack presentationstack presentation
stack presentation
 
Linklist
LinklistLinklist
Linklist
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 

Destaque

Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structure
Tushar Aneyrao
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
dchuynh
 

Destaque (20)

Linked list
Linked listLinked list
Linked list
 
Linked lists
Linked listsLinked lists
Linked lists
 
Link List
Link ListLink List
Link List
 
linked list
linked list linked list
linked list
 
Linked list
Linked listLinked list
Linked list
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structure
 
Linked lists
Linked listsLinked lists
Linked lists
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Single linked list
Single linked listSingle linked list
Single linked list
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
 
Infix to postfix
Infix to postfixInfix to postfix
Infix to postfix
 
Linked List
Linked ListLinked List
Linked List
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Linkedlist1
Linkedlist1Linkedlist1
Linkedlist1
 
LinkedList vs Arraylist- an in depth look at java.util.LinkedList
LinkedList vs Arraylist- an in depth look at java.util.LinkedListLinkedList vs Arraylist- an in depth look at java.util.LinkedList
LinkedList vs Arraylist- an in depth look at java.util.LinkedList
 
Link list CSE ( Data structure ) .
Link list CSE  ( Data structure ) .Link list CSE  ( Data structure ) .
Link list CSE ( Data structure ) .
 
File Handling In C++(OOPs))
File Handling In C++(OOPs))File Handling In C++(OOPs))
File Handling In C++(OOPs))
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IO
 

Semelhante a Single linked list

–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
pasqualealvarez467
 
I am not able to complete the last function. Could anyone please hel.pdf
I am not able to complete the last function. Could anyone please hel.pdfI am not able to complete the last function. Could anyone please hel.pdf
I am not able to complete the last function. Could anyone please hel.pdf
fantoosh1
 
Linked List Implementation of Queue in C
Linked List Implementation of Queue in CLinked List Implementation of Queue in C
Linked List Implementation of Queue in C
Kasun Ranga Wijeweera
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
ritu1806
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribd
Amit Kapoor
 
Please solve the TODO parts of the following probelm incl.pdf
Please solve the TODO parts of the following probelm  incl.pdfPlease solve the TODO parts of the following probelm  incl.pdf
Please solve the TODO parts of the following probelm incl.pdf
aggarwalopticalsco
 
C++ Program to Implement Singly Linked List #includei.pdf
  C++ Program to Implement Singly Linked List  #includei.pdf  C++ Program to Implement Singly Linked List  #includei.pdf
C++ Program to Implement Singly Linked List #includei.pdf
anupambedcovers
 
Write code in c++ Program to a topological sort on a graph Program pl.docx
Write code in c++ Program to a topological sort on a graph  Program pl.docxWrite code in c++ Program to a topological sort on a graph  Program pl.docx
Write code in c++ Program to a topological sort on a graph Program pl.docx
noreendchesterton753
 

Semelhante a Single linked list (20)

–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
 
I am not able to complete the last function. Could anyone please hel.pdf
I am not able to complete the last function. Could anyone please hel.pdfI am not able to complete the last function. Could anyone please hel.pdf
I am not able to complete the last function. Could anyone please hel.pdf
 
Linked List Implementation of Queue in C
Linked List Implementation of Queue in CLinked List Implementation of Queue in C
Linked List Implementation of Queue in C
 
Linked lists - Exercises
Linked lists - ExercisesLinked lists - Exercises
Linked lists - Exercises
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
Linked lists
Linked listsLinked lists
Linked lists
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribd
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
C programming
C programmingC programming
C programming
 
Please solve the TODO parts of the following probelm incl.pdf
Please solve the TODO parts of the following probelm  incl.pdfPlease solve the TODO parts of the following probelm  incl.pdf
Please solve the TODO parts of the following probelm incl.pdf
 
Effective C#
Effective C#Effective C#
Effective C#
 
Dsprograms(2nd cse)
Dsprograms(2nd cse)Dsprograms(2nd cse)
Dsprograms(2nd cse)
 
Singly Linked List
Singly Linked ListSingly Linked List
Singly Linked List
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
 
C++ Program to Implement Singly Linked List #includei.pdf
  C++ Program to Implement Singly Linked List  #includei.pdf  C++ Program to Implement Singly Linked List  #includei.pdf
C++ Program to Implement Singly Linked List #includei.pdf
 
Nbvtalkatbzaonencryptionpuzzles
NbvtalkatbzaonencryptionpuzzlesNbvtalkatbzaonencryptionpuzzles
Nbvtalkatbzaonencryptionpuzzles
 
Nbvtalkatbzaonencryptionpuzzles
NbvtalkatbzaonencryptionpuzzlesNbvtalkatbzaonencryptionpuzzles
Nbvtalkatbzaonencryptionpuzzles
 
Write code in c++ Program to a topological sort on a graph Program pl.docx
Write code in c++ Program to a topological sort on a graph  Program pl.docxWrite code in c++ Program to a topological sort on a graph  Program pl.docx
Write code in c++ Program to a topological sort on a graph Program pl.docx
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
Pointers
PointersPointers
Pointers
 

Último

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
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
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 

Último (20)

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
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
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.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
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 

Single linked list

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. If list is empty i.e. P==NULL P Q NULL
  • 8. If list is empty i.e. P==NULL P Q p=(struct node *) malloc(sizeof(struct node))
  • 9. If list is empty i.e. P==NULL P Q p=(struct node *) malloc(sizeof(struct node)) P->data=num 10
  • 10. If list is empty i.e. P==NULL P Q p=(struct node *) malloc(sizeof(struct node)) P->data=num 10 P->link=NULL NULL
  • 11. If list is not empty i.e. p!=NULL 10 20 30 Node A Node B Node C NULL P Q
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21. If position is 1 10 20 30 Node A Node B Node C NULL Q P
  • 22. If position is 1 10 20 30 Node A Node B Node C NULL Q P p=(struct node *) malloc(sizeof(struct node));
  • 23. If position is 1 10 20 30 Node A Node B Node C NULL Q P p=(struct node *) malloc(sizeof(struct node)); p->data=num 5
  • 24. If position is 1 10 20 30 Node A Node B Node C NULL Q P p=(struct node *) malloc(sizeof(struct node)); p->data=num; 5 p->link=q;
  • 25. If position is greater than 1 10 20 30 Node A Node B Node C NULL Q P Suppose a node is to be inserted at position 3.
  • 26. 10 20 30 Node A Node B Node C NULL P Q for(i=1;i<=3-2;i++) { q=q->link; }
  • 27. 10 20 30 Node A Node B Node C NULL P Q for(i=1;i<=3-2;i++) { q=q->link; } temp
  • 28. 10 20 30 Node A Node B Node C NULL P Q for(i=1;i<=3-2;i++) { q=q->link; } temp
  • 29. 10 20 30 Node A Node B Node C NULL P Q for(i=1;i<=3-2;i++) { q=q->link; } temp Node BC q->link=(struct node *) malloc(sizeof(struct node));
  • 30. 10 20 30 Node A Node B Node C NULL P Q for(i=1;i<=3-2;i++) { q=q->link; } temp Node BC q->link=(struct node *) malloc(sizeof(struct node)); 25 q->link->data=num;
  • 31. 10 20 30 Node A Node B Node C NULL P Q for(i=1;i<=3-2;i++) { q=q->link; } temp Node BC q->link=(struct node *) malloc(sizeof(struct node)); 25 q->link->data=num; q->link->link=temp;
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41. If position is 1 10 20 30 10 NULL Node A Node B Node C Node D P Q
  • 42.
  • 43. If position is 1 10 20 30 10 NULL Node A Node B Node C Node D P Q
  • 44.
  • 45.
  • 46.
  • 47.
  • 48. SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link) { if(i->data>j->data) { temp=i->data; i->data=j->data; j->data=temp; } } } 7 6 3 Node A Node B Node C 1 NULL Node D i j
  • 49. SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link) { if(i->data>j->data) { temp=i->data; i->data=j->data; j->data=temp; } } } 7 6 3 Node A Node B Node C 1 NULL Node D i j
  • 50. SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link) { if(i->data>j->data) { temp=i->data; i->data=j->data; j->data=temp; } } } 6 7 3 Node A Node B Node C 1 NULL Node D i j
  • 51. SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link) { if(i->data>j->data) { temp=i->data; i->data=j->data; j->data=temp; } } } 3 7 6 Node A Node B Node C 1 NULL Node D i j
  • 52. SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link) { if(i->data>j->data) { temp=i->data; i->data=j->data; j->data=temp; } } } 3 7 6 Node A Node B Node C 1 NULL Node D i j
  • 53. SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link) { if(i->data>j->data) { temp=i->data; i->data=j->data; j->data=temp; } } } 1 7 6 Node A Node B Node C 3 NULL Node D i j
  • 54. SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link) { if(i->data>j->data) { temp=i->data; i->data=j->data; j->data=temp; } } } 1 6 7 Node A Node B Node C 3 NULL Node D i j
  • 55. SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link) { if(i->data>j->data) { temp=i->data; i->data=j->data; j->data=temp; } } } 1 3 7 Node A Node B Node C 6 NULL Node D i j
  • 56. SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link) { if(i->data>j->data) { temp=i->data; i->data=j->data; j->data=temp; } } } 1 3 7 Node A Node B Node C 6 NULL Node D i j
  • 57. SORTING Traversal & comparison: for(i=p;i!=NULL;i=i->link) { for(j=i->link;j!=NULL;j=j->link) { if(i->data>j->data) { temp=i->data; i->data=j->data; j->data=temp; } } } 1 3 6 Node A Node B Node C 7 NULL Node D i j
  • 58.