SlideShare a Scribd company logo
Algorithm to insert a node at the beginning of single linked list:
Let headbe a pointerthat storesthe addressof firstnode
step1: Readthe value to insertedintolinkedlist
step2: create a newnode usingmallocfunction
step3: Assignthe value readtothe data fieldof newnode (newnode->data=value)
step4: setthe nextof newnode tohead (newnode->next=head)
step5: setthe headpointertonewnode (head=newnode)
Single linkedlistBefore insertionofnewnode
Single linkedlistAfterinsertionof newnode:
1. creationof newnode at address 600 and value to be insertedinto linkedlist= 60
2. Linking newnode to existinglinkedlist
Algorithm to insert a node at the end of single linked list:
Let headbe a pointerthat storesthe addressof firstnode
step1: Readthe value to insertedintolinkedlist
step2: create a newnode usingmallocfunction
step3: Assignthe value readtothe data fieldof newnode
step4: if there isno linkedlistthennewnode becomesfirstnode
step5: otherwise gotothe lastnode inlinkedlist
Step5.1: attach newnode tolastnode (lastnode ->next=newnode)
Step5.2: newnode->next=NULL
head
100 200
200 NULL10 20
newnode
60
20
head
600
100
100
100 200
200
60 10 20
NULL
Single linkedlistBefore insertionofnewnode
Single linkedlistAfterinsertionof newnode:
1. creationof newnode at address 600 and value to be insertedinto linkedlist= 60
2. Linking newnode to existinglinkedlist
Algorithm to insert a node at a given position of single linked list:
Let headbe a pointerthat storesthe addressof firstnode
step1: Readthe value to insertedintolinkedlistandthe positionatwhichnewnodehastobe inserted
step2: create a newnode usingmallocfunction
step3: Assignthe value readtothe data fieldof newnode
step4: store the node before the givenposition inapointerc
step5: newnode->next=c->next
step6: c->next= newnode
Single linkedlistBefore insertionofnewnode
Single linkedlistAfterinsertionof newnode:
1. creationof newnode at address 600 and value to be insertedinto linkedlist= 60 position=2
head
100 200
200 NULL10 20
newnode
60
20
head
100
100
200
200 600
600
10 20 60
head
NULL
100 200
200 NULL10 20
newnode
60
2. Linking newnode to existinglinkedlist
Algorithm to delete a node at the beginning of single linked list:
Let headbe a pointerthat storesthe addressof firstnode
step1: If there isno linkedlistthenprintLinkedlistisempty
step2: If linkedlist exists
step2.1: delete the firstnode
step2.2: secondnode becomesfirstnode
Single linkedlistBefore deletion
Single linkedlistAfterdeletion:
Algorithm to delete a node at the end of single linked list:
Let headbe a pointerthat storesthe addressof firstnode
step1: If there isno linkedlistthenprintLinkedlist isempty
step2: If linkedlistexists
step2.1: move tolast but one node andstore the addressof lastbut one node inpointerc
step2.2: store the addressof last node inpointerpand detele the lastnode (free(p))
step2.3: c->next= NULL
20
c
600
100
200
600
200
60
10 20
NULL
NULL
head
100 200
20010 20
head
200
100NULL20
NULL
Single linkedlistBefore deletion
Single linkedlistAfterdeletion:
Algorithm to delete a node at given position of single linked list:
Let headbe a pointerthat storesthe addressof firstnode
step1: If there isno linkedlistthenprintLinkedlistisempty
step2: If linkedlistexists
step2.1: Readthe positionatwhichthe node has to deleted
step2.2: Store the addressof node before the tobe deletednodeinpointerc
step2.3: c->next= c->next->next
step2.4: delete the node atgivenposition
Single linkedlistBefore deletion
Single linkedlistAfterdeletingthe node at position2 :
Algorithm to display the elements of single linked list
Let headbe a pointerthat storesthe addressof firstnode
step1: If there isno linkedlistthenprintLinkedlistisempty
step2: If linkedlistexistsstore the addressof firstnode inpointerc( c = head)
step2.1: printthe data fieldinc (printc->data)
step2.2 move c to store the address of nextnode ( c = c-> next)
step3: go to step2 until c is notequal to NULL
NULL
head
100 200
20010 20
head
100
100NULL10
NULL
NULL
C
100 200
20010 20 300
300
30 NULL
NULL
head
100 300
30010 30 NULL
Singlelinked list

More Related Content

PPTX
Doubly circular linked list
Roshan Chaudhary
 
PPT
Lect 11-12 Zaheer Abbas
Information Technology Center
 
PPT
Link list
Ravi Gautam
 
PDF
Singly linked list
Amar Jukuntla
 
DOC
Linked List
Md gulam sarwar
 
PPTX
Insertion into linked lists
MrDavinderSingh
 
PPT
Data Structure Lecture 5
Teksify
 
PPTX
Linked list
Dr. Shashank Shetty
 
Doubly circular linked list
Roshan Chaudhary
 
Lect 11-12 Zaheer Abbas
Information Technology Center
 
Link list
Ravi Gautam
 
Singly linked list
Amar Jukuntla
 
Linked List
Md gulam sarwar
 
Insertion into linked lists
MrDavinderSingh
 
Data Structure Lecture 5
Teksify
 
Linked list
Dr. Shashank Shetty
 

What's hot (19)

PPTX
Doubly linked list (animated)
DivyeshKumar Jagatiya
 
PPTX
Doubly & Circular Linked Lists
Afaq Mansoor Khan
 
PPSX
Ds06 linked list- insert a node at beginning
jyoti_lakhani
 
PPTX
5.Linked list
Mandeep Singh
 
PDF
Circular linked list
maamir farooq
 
PDF
Linked list
maamir farooq
 
PPTX
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
PPTX
Link list presentation slide(Daffodil international university)
shah alom
 
PDF
Finalpresentationfordatastructure 161207052319
Shaid Bin MD. Sifat
 
PPTX
Linked list
MahammadAdil
 
PPTX
Doubly Linked List || Operations || Algorithms
Shubham Sharma
 
PPTX
linked list using c
Venkat Reddy
 
PPT
Linked list
eShikshak
 
PPT
Data structure lecture 5
Kumar
 
ODP
Linked List
Keshav Vaswani
 
PPTX
Doubly Linked List
Ninad Mankar
 
PPT
Linkedlists
Rajendran
 
PPTX
Linked lists in Data Structure
Muhazzab Chouhadry
 
PPTX
Double Linked List (Algorithm)
Huba Akhtar
 
Doubly linked list (animated)
DivyeshKumar Jagatiya
 
Doubly & Circular Linked Lists
Afaq Mansoor Khan
 
Ds06 linked list- insert a node at beginning
jyoti_lakhani
 
5.Linked list
Mandeep Singh
 
Circular linked list
maamir farooq
 
Linked list
maamir farooq
 
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
Link list presentation slide(Daffodil international university)
shah alom
 
Finalpresentationfordatastructure 161207052319
Shaid Bin MD. Sifat
 
Linked list
MahammadAdil
 
Doubly Linked List || Operations || Algorithms
Shubham Sharma
 
linked list using c
Venkat Reddy
 
Linked list
eShikshak
 
Data structure lecture 5
Kumar
 
Linked List
Keshav Vaswani
 
Doubly Linked List
Ninad Mankar
 
Linkedlists
Rajendran
 
Linked lists in Data Structure
Muhazzab Chouhadry
 
Double Linked List (Algorithm)
Huba Akhtar
 
Ad

Similar to Singlelinked list (20)

PPTX
LinkedList-VJ-V2.pptx Analysis of Algorithms and Data Structures
ryadavrohit26
 
PPTX
Linked list
RahulGandhi110
 
PPTX
Singly Linked List_Operations-Traversal.pptx
ssusera965f6
 
PPTX
Lec3-Linked list.pptx
FaheemMahmood2
 
PPT
Mi 103 linked list
Amit Vats
 
PPTX
Insertion operation
kalpanasatishkumar
 
PPT
Algo>ADT list & linked list
Ain-ul-Moiz Khawaja
 
PPT
Data Structures with C Linked List
Reazul Islam
 
PPT
17 linkedlist (1)
Himadri Sen Gupta
 
PPT
Singly link list
Rojin Khadka
 
PPT
Linkedlist
Masud Parvaze
 
PPTX
Linked List Presentation in data structurepptx
nikhilcse1
 
PDF
Linked Lists.pdf
Kaynattariq1
 
PPTX
Linked List Representation of a Linked List.pptx
AAUsH2
 
PPTX
singlelinkedlistasdfghzxcvbnmqwertyuiopa
rabailasghar3
 
PPTX
Data structures linked list introduction.pptx
Kalpana Mohan
 
PPT
linked-list.ppt
DikkySuryadiSKomMKom
 
PDF
I have been tasked to write a code for a Singly Linked list that inc.pdf
arkmuzikllc
 
PPT
Abstract data types
JAGDEEPKUMAR23
 
PPTX
Linked list
Arbind Mandal
 
LinkedList-VJ-V2.pptx Analysis of Algorithms and Data Structures
ryadavrohit26
 
Linked list
RahulGandhi110
 
Singly Linked List_Operations-Traversal.pptx
ssusera965f6
 
Lec3-Linked list.pptx
FaheemMahmood2
 
Mi 103 linked list
Amit Vats
 
Insertion operation
kalpanasatishkumar
 
Algo>ADT list & linked list
Ain-ul-Moiz Khawaja
 
Data Structures with C Linked List
Reazul Islam
 
17 linkedlist (1)
Himadri Sen Gupta
 
Singly link list
Rojin Khadka
 
Linkedlist
Masud Parvaze
 
Linked List Presentation in data structurepptx
nikhilcse1
 
Linked Lists.pdf
Kaynattariq1
 
Linked List Representation of a Linked List.pptx
AAUsH2
 
singlelinkedlistasdfghzxcvbnmqwertyuiopa
rabailasghar3
 
Data structures linked list introduction.pptx
Kalpana Mohan
 
linked-list.ppt
DikkySuryadiSKomMKom
 
I have been tasked to write a code for a Singly Linked list that inc.pdf
arkmuzikllc
 
Abstract data types
JAGDEEPKUMAR23
 
Linked list
Arbind Mandal
 
Ad

More from Lakshmi Sarvani Videla (20)

DOCX
Data Science Using Python
Lakshmi Sarvani Videla
 
DOCX
Programs on multithreading
Lakshmi Sarvani Videla
 
PPT
Menu Driven programs in Java
Lakshmi Sarvani Videla
 
DOCX
Recursion in C
Lakshmi Sarvani Videla
 
DOCX
Simple questions on structures concept
Lakshmi Sarvani Videla
 
PPTX
Errors incompetitiveprogramming
Lakshmi Sarvani Videla
 
DOCX
Relational Operators in C
Lakshmi Sarvani Videla
 
PPTX
Recursive functions in C
Lakshmi Sarvani Videla
 
PPTX
Function Pointer in C
Lakshmi Sarvani Videla
 
PPTX
Functions
Lakshmi Sarvani Videla
 
DOCX
Java sessionnotes
Lakshmi Sarvani Videla
 
PPTX
Functions in python3
Lakshmi Sarvani Videla
 
PPTX
Dictionary
Lakshmi Sarvani Videla
 
DOCX
DataStructures notes
Lakshmi Sarvani Videla
 
DOCX
Solutionsfor co2 C Programs for data structures
Lakshmi Sarvani Videla
 
DOCX
C programs
Lakshmi Sarvani Videla
 
Data Science Using Python
Lakshmi Sarvani Videla
 
Programs on multithreading
Lakshmi Sarvani Videla
 
Menu Driven programs in Java
Lakshmi Sarvani Videla
 
Recursion in C
Lakshmi Sarvani Videla
 
Simple questions on structures concept
Lakshmi Sarvani Videla
 
Errors incompetitiveprogramming
Lakshmi Sarvani Videla
 
Relational Operators in C
Lakshmi Sarvani Videla
 
Recursive functions in C
Lakshmi Sarvani Videla
 
Function Pointer in C
Lakshmi Sarvani Videla
 
Java sessionnotes
Lakshmi Sarvani Videla
 
Functions in python3
Lakshmi Sarvani Videla
 
DataStructures notes
Lakshmi Sarvani Videla
 
Solutionsfor co2 C Programs for data structures
Lakshmi Sarvani Videla
 

Recently uploaded (20)

PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
The Future of Artificial Intelligence (AI)
Mukul
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 

Singlelinked list

  • 1. Algorithm to insert a node at the beginning of single linked list: Let headbe a pointerthat storesthe addressof firstnode step1: Readthe value to insertedintolinkedlist step2: create a newnode usingmallocfunction step3: Assignthe value readtothe data fieldof newnode (newnode->data=value) step4: setthe nextof newnode tohead (newnode->next=head) step5: setthe headpointertonewnode (head=newnode) Single linkedlistBefore insertionofnewnode Single linkedlistAfterinsertionof newnode: 1. creationof newnode at address 600 and value to be insertedinto linkedlist= 60 2. Linking newnode to existinglinkedlist Algorithm to insert a node at the end of single linked list: Let headbe a pointerthat storesthe addressof firstnode step1: Readthe value to insertedintolinkedlist step2: create a newnode usingmallocfunction step3: Assignthe value readtothe data fieldof newnode step4: if there isno linkedlistthennewnode becomesfirstnode step5: otherwise gotothe lastnode inlinkedlist Step5.1: attach newnode tolastnode (lastnode ->next=newnode) Step5.2: newnode->next=NULL head 100 200 200 NULL10 20 newnode 60 20 head 600 100 100 100 200 200 60 10 20 NULL
  • 2. Single linkedlistBefore insertionofnewnode Single linkedlistAfterinsertionof newnode: 1. creationof newnode at address 600 and value to be insertedinto linkedlist= 60 2. Linking newnode to existinglinkedlist Algorithm to insert a node at a given position of single linked list: Let headbe a pointerthat storesthe addressof firstnode step1: Readthe value to insertedintolinkedlistandthe positionatwhichnewnodehastobe inserted step2: create a newnode usingmallocfunction step3: Assignthe value readtothe data fieldof newnode step4: store the node before the givenposition inapointerc step5: newnode->next=c->next step6: c->next= newnode Single linkedlistBefore insertionofnewnode Single linkedlistAfterinsertionof newnode: 1. creationof newnode at address 600 and value to be insertedinto linkedlist= 60 position=2 head 100 200 200 NULL10 20 newnode 60 20 head 100 100 200 200 600 600 10 20 60 head NULL 100 200 200 NULL10 20 newnode 60
  • 3. 2. Linking newnode to existinglinkedlist Algorithm to delete a node at the beginning of single linked list: Let headbe a pointerthat storesthe addressof firstnode step1: If there isno linkedlistthenprintLinkedlistisempty step2: If linkedlist exists step2.1: delete the firstnode step2.2: secondnode becomesfirstnode Single linkedlistBefore deletion Single linkedlistAfterdeletion: Algorithm to delete a node at the end of single linked list: Let headbe a pointerthat storesthe addressof firstnode step1: If there isno linkedlistthenprintLinkedlist isempty step2: If linkedlistexists step2.1: move tolast but one node andstore the addressof lastbut one node inpointerc step2.2: store the addressof last node inpointerpand detele the lastnode (free(p)) step2.3: c->next= NULL 20 c 600 100 200 600 200 60 10 20 NULL NULL head 100 200 20010 20 head 200 100NULL20 NULL
  • 4. Single linkedlistBefore deletion Single linkedlistAfterdeletion: Algorithm to delete a node at given position of single linked list: Let headbe a pointerthat storesthe addressof firstnode step1: If there isno linkedlistthenprintLinkedlistisempty step2: If linkedlistexists step2.1: Readthe positionatwhichthe node has to deleted step2.2: Store the addressof node before the tobe deletednodeinpointerc step2.3: c->next= c->next->next step2.4: delete the node atgivenposition Single linkedlistBefore deletion Single linkedlistAfterdeletingthe node at position2 : Algorithm to display the elements of single linked list Let headbe a pointerthat storesthe addressof firstnode step1: If there isno linkedlistthenprintLinkedlistisempty step2: If linkedlistexistsstore the addressof firstnode inpointerc( c = head) step2.1: printthe data fieldinc (printc->data) step2.2 move c to store the address of nextnode ( c = c-> next) step3: go to step2 until c is notequal to NULL NULL head 100 200 20010 20 head 100 100NULL10 NULL NULL C 100 200 20010 20 300 300 30 NULL NULL head 100 300 30010 30 NULL