SlideShare a Scribd company logo
Singly Linked List-
Insertion operation
Some real time Applications of Linked List
Image Viewer
Web browser
Music Player
Insertion operation
There are three possible cases when we want to insert an element in the linked
list-
• Insertion of a node as a head(first) node
• Insertion of a node as a last node
• Insertion of a node after some node
Steps to insert a node at the beginning of singly linked list
1. Create a new node, say newnode points to the newly created node.
1000 1500 2000
1500 2000
3000
Steps to insert a node at the beginning of singly linked list
(Cont…)
2. Link the newly created node with the head node, i.e. the newnode will now
point to head node.
newnode -> next = head;
1000 1500 2000
1500 2000
1000
Steps to insert a node at the beginning of singly linked list
(Cont…)
3. Make the new node as the head node, i.e. now head node will point to newnode
head = newnode;
1500 2000
1000
1000 1500 2000
Algorithm to insert a node as first node
Step 1. Create a new node and assign the address say newnode.
Step 2. Assign newnode -> data = value;
Step 3. Assign newnode -> next = head;
Step 4. Set head = newnode;
Step 5. EXIT
C Routine to insert node at beginning of List
void insertNodeAtBeginning(int data)
{
struct node *newNode;
newNode = (struct node*)malloc(sizeof(struct node));
newNode->data = data; // data part
newNode->next = head; // Link address part
head = newNode; // Make newNode as first node
}
Steps to insert node at the end of Singly linked list
Create a new node and make sure that the address part of the new node points
to NULL i.e. newNode->next=NULL
1000 1500 2000
3000
2000
1500
Steps to insert node at the end of Singly linked list Cont….
2. Traverse to the last node of the linked list and connect the last node of the list
with the new node, i.e. last node will now point to new node. (temp->next =
newNode).
temp -> next = newnode;
1000 1500 2000
3000
3000
1500
2000
Algorithm to insert a node as last node
1. Create a node, say newnode.
2. Assign newnode -> data = value;
Set newnode -> next = NULL;
3. Set temp = head;
WHILE temp->next != NULL
temp = temp->next;
temp->next = newnode;
temp
temp
temp
temp = temp->next;
temp = temp->next;
temp->next != NULL
C Routine to insert a node as last node
void insertNodeAtEnd(int data)
{
struct node *newNode, *temp;
newNode = (struct node*)malloc(sizeof(struct node));
newNode->data = data; //data part
newNode->next = NULL;
temp = head;
// Traverse to the last node
while(temp->next != NULL)
temp = temp->next;
temp->next = newNode; // Link address part
}
Steps to insert a node at any intermediate position
based on key value of singly linked list
1. Create a new node say newnode
1000 500 2000 2500
1500
2500
2000
500
Steps to insert a node at any intermediate position based on
key value of singly linked list
2. Get the search key value from user and compare each node’s data.
Search Key =
20
If temp ->data== key
then
newnode->next=temp->next;
1000 500 2000 2500
1500
2000
Steps to insert a node at any intermediate position
based on key value of singly linked list
temp-> next =newnode;
2000
1000 500 2000 2500
1500
1500
2500
500
Algorithm to insert a node at any intermediate position
based on key value of singly linked list
. Create a node, say newnode.
Assign newnode -> data = value;
Get the search key value as key
set temp = head;
Do
If temp->data == key;
newnode-> next=temp->
next;
temp->next= newnode;
Else
temp = temp->next;
WHILE temp->next != NULL

More Related Content

What's hot

Textile
TextileTextile
Parallel arrays in python
Parallel arrays in pythonParallel arrays in python
Parallel arrays in python
Forrester High School
 
RxSubject And Operators
RxSubject And OperatorsRxSubject And Operators
RxSubject And Operators
Seven Peaks Speaks
 
เกมส์จับคู่
เกมส์จับคู่เกมส์จับคู่
เกมส์จับคู่Aeew Autaporn
 
Records in Python
Records in PythonRecords in Python
Records in Python
Forrester High School
 
Dynamically linked queues
Dynamically linked queuesDynamically linked queues
Dynamically linked queuesJonghoon Park
 
Part2 from math import * from simpson import * k=1 def f(x): return (exp(-(x...
Part2 from math import * from simpson import *  k=1 def f(x): return (exp(-(x...Part2 from math import * from simpson import *  k=1 def f(x): return (exp(-(x...
Part2 from math import * from simpson import * k=1 def f(x): return (exp(-(x...
hwbloom25
 
Qtp Scripts
Qtp ScriptsQtp Scripts
Qtp Scripts
G.C Reddy
 
Machine Learning In Ruby
Machine Learning In RubyMachine Learning In Ruby
Machine Learning In Ruby
Brad Arner
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
Noritada Shimizu
 
3. basics of python
3. basics of python3. basics of python
3. basics of python
Vishnu Vardhan
 
Class array
Class arrayClass array
Class arraynky92
 
Grand Central Dispatch
Grand Central DispatchGrand Central Dispatch
Grand Central Dispatch
Joachim Bengtsson
 
All you need to know about Callbacks, Promises, Generators
All you need to know about Callbacks, Promises, GeneratorsAll you need to know about Callbacks, Promises, Generators
All you need to know about Callbacks, Promises, Generators
Brainhub
 
Document
DocumentDocument
Document
AjitRaj12
 
7th lab
7th lab7th lab
7th lab
rajiprateesh
 
Javascript Continues Integration in Jenkins with AngularJS
Javascript Continues Integration in Jenkins with AngularJSJavascript Continues Integration in Jenkins with AngularJS
Javascript Continues Integration in Jenkins with AngularJSLadislav Prskavec
 

What's hot (20)

Textile
TextileTextile
Textile
 
Parallel arrays in python
Parallel arrays in pythonParallel arrays in python
Parallel arrays in python
 
RxSubject And Operators
RxSubject And OperatorsRxSubject And Operators
RxSubject And Operators
 
เกมส์จับคู่
เกมส์จับคู่เกมส์จับคู่
เกมส์จับคู่
 
Records in Python
Records in PythonRecords in Python
Records in Python
 
Dynamically linked queues
Dynamically linked queuesDynamically linked queues
Dynamically linked queues
 
Part2 from math import * from simpson import * k=1 def f(x): return (exp(-(x...
Part2 from math import * from simpson import *  k=1 def f(x): return (exp(-(x...Part2 from math import * from simpson import *  k=1 def f(x): return (exp(-(x...
Part2 from math import * from simpson import * k=1 def f(x): return (exp(-(x...
 
Clock
ClockClock
Clock
 
Qtp Scripts
Qtp ScriptsQtp Scripts
Qtp Scripts
 
Machine Learning In Ruby
Machine Learning In RubyMachine Learning In Ruby
Machine Learning In Ruby
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
3. basics of python
3. basics of python3. basics of python
3. basics of python
 
Class array
Class arrayClass array
Class array
 
Grand Central Dispatch
Grand Central DispatchGrand Central Dispatch
Grand Central Dispatch
 
All you need to know about Callbacks, Promises, Generators
All you need to know about Callbacks, Promises, GeneratorsAll you need to know about Callbacks, Promises, Generators
All you need to know about Callbacks, Promises, Generators
 
Document
DocumentDocument
Document
 
7th lab
7th lab7th lab
7th lab
 
Javascript Continues Integration in Jenkins with AngularJS
Javascript Continues Integration in Jenkins with AngularJSJavascript Continues Integration in Jenkins with AngularJS
Javascript Continues Integration in Jenkins with AngularJS
 
1
11
1
 
Strings1
Strings1Strings1
Strings1
 

Similar to Insertion operation

17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
Himadri Sen Gupta
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
fortmdu
 
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
Mani .S (Specialization in Semantic Web)
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
Afaq Mansoor Khan
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
Masud Parvaze
 
Linked list
Linked listLinked list
Linked list
RahulGandhi110
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
Amar Jukuntla
 
Linked list
Linked listLinked list
Linked list
Md. Afif Al Mamun
 
Singlelinked list
Singlelinked listSinglelinked list
Singlelinked list
Lakshmi Sarvani Videla
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
MeghaKulkarni27
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked listAmit Vats
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
DaniyalAli81
 
Linked list
Linked listLinked list
Linked list
A. S. M. Shafi
 
Lec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdfLec-4_Linked-List (1).pdf
Lec-4_Linked-List (1).pdf
KylaMaeGarcia1
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
Stack - PPT Slides.pptx-data sturutures and algorithanms
Stack - PPT Slides.pptx-data sturutures and algorithanmsStack - PPT Slides.pptx-data sturutures and algorithanms
Stack - PPT Slides.pptx-data sturutures and algorithanms
AdithaBuwaneka
 
Data Structure Suppose a singly linked list is implemented with refere.docx
Data Structure Suppose a singly linked list is implemented with refere.docxData Structure Suppose a singly linked list is implemented with refere.docx
Data Structure Suppose a singly linked list is implemented with refere.docx
cliftonl1
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
fathimahardwareelect
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
Programming Homework Help
 

Similar to Insertion operation (20)

17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
 
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
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
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
 
Singlelinked list
Singlelinked listSinglelinked list
Singlelinked list
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked list
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
Linked list
Linked listLinked 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
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
Cpp lernaufgabe linked_list
Cpp lernaufgabe linked_listCpp lernaufgabe linked_list
Cpp lernaufgabe linked_list
 
Stack - PPT Slides.pptx-data sturutures and algorithanms
Stack - PPT Slides.pptx-data sturutures and algorithanmsStack - PPT Slides.pptx-data sturutures and algorithanms
Stack - PPT Slides.pptx-data sturutures and algorithanms
 
Data Structure Suppose a singly linked list is implemented with refere.docx
Data Structure Suppose a singly linked list is implemented with refere.docxData Structure Suppose a singly linked list is implemented with refere.docx
Data Structure Suppose a singly linked list is implemented with refere.docx
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 

Recently uploaded

TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 

Recently uploaded (20)

TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 

Insertion operation

  • 2. Some real time Applications of Linked List Image Viewer Web browser Music Player
  • 3. Insertion operation There are three possible cases when we want to insert an element in the linked list- • Insertion of a node as a head(first) node • Insertion of a node as a last node • Insertion of a node after some node
  • 4. Steps to insert a node at the beginning of singly linked list 1. Create a new node, say newnode points to the newly created node. 1000 1500 2000 1500 2000 3000
  • 5. Steps to insert a node at the beginning of singly linked list (Cont…) 2. Link the newly created node with the head node, i.e. the newnode will now point to head node. newnode -> next = head; 1000 1500 2000 1500 2000 1000
  • 6. Steps to insert a node at the beginning of singly linked list (Cont…) 3. Make the new node as the head node, i.e. now head node will point to newnode head = newnode; 1500 2000 1000 1000 1500 2000
  • 7. Algorithm to insert a node as first node Step 1. Create a new node and assign the address say newnode. Step 2. Assign newnode -> data = value; Step 3. Assign newnode -> next = head; Step 4. Set head = newnode; Step 5. EXIT
  • 8. C Routine to insert node at beginning of List void insertNodeAtBeginning(int data) { struct node *newNode; newNode = (struct node*)malloc(sizeof(struct node)); newNode->data = data; // data part newNode->next = head; // Link address part head = newNode; // Make newNode as first node }
  • 9. Steps to insert node at the end of Singly linked list Create a new node and make sure that the address part of the new node points to NULL i.e. newNode->next=NULL 1000 1500 2000 3000 2000 1500
  • 10. Steps to insert node at the end of Singly linked list Cont…. 2. Traverse to the last node of the linked list and connect the last node of the list with the new node, i.e. last node will now point to new node. (temp->next = newNode). temp -> next = newnode; 1000 1500 2000 3000 3000 1500 2000
  • 11. Algorithm to insert a node as last node 1. Create a node, say newnode. 2. Assign newnode -> data = value; Set newnode -> next = NULL; 3. Set temp = head; WHILE temp->next != NULL temp = temp->next; temp->next = newnode; temp temp temp temp = temp->next; temp = temp->next; temp->next != NULL
  • 12. C Routine to insert a node as last node void insertNodeAtEnd(int data) { struct node *newNode, *temp; newNode = (struct node*)malloc(sizeof(struct node)); newNode->data = data; //data part newNode->next = NULL; temp = head; // Traverse to the last node while(temp->next != NULL) temp = temp->next; temp->next = newNode; // Link address part }
  • 13. Steps to insert a node at any intermediate position based on key value of singly linked list 1. Create a new node say newnode 1000 500 2000 2500 1500 2500 2000 500
  • 14. Steps to insert a node at any intermediate position based on key value of singly linked list 2. Get the search key value from user and compare each node’s data. Search Key = 20 If temp ->data== key then newnode->next=temp->next; 1000 500 2000 2500 1500 2000
  • 15. Steps to insert a node at any intermediate position based on key value of singly linked list temp-> next =newnode; 2000 1000 500 2000 2500 1500 1500 2500 500
  • 16. Algorithm to insert a node at any intermediate position based on key value of singly linked list . Create a node, say newnode. Assign newnode -> data = value; Get the search key value as key set temp = head; Do If temp->data == key; newnode-> next=temp-> next; temp->next= newnode; Else temp = temp->next; WHILE temp->next != NULL