SlideShare una empresa de Scribd logo
1 de 9
LINKED LIST OPERATIONS
By,
Shashank Shetty
Assistant Professor,
Department of ISE
NMAMIT, Nitte
Shashankshetty@nitte.edu.in
Inserting a node into a SLL
There are many ways you might want to
insert a new node into a list:
As the new first element
As the new last element
 In the middle of the two nodes or in some
designated position.
Shashankshetty@nitte.edu.in
25
1) Insert a node at the beginning of the list
// Algorithm : Insertion (Item)
// Description : Inserts a node at the beginning of
the SLL
Step1: Start
Step 2: NewNode=getnode()
NewNode -> link = NULL
NewNode -> info = Item
Step 3: [ If the Linked list is empty, then the New
Node Created is a first node or Head Node]
if(Head==NULL)
Head=NewNode
return
End if
Step 4: [If the linked list is not empty]
NewNode -> link= Head
Head= NewNode
Free(NewNode)
Step 5: Return (Stop)
Item NULL
NewNode
Head
NULL
4 6 NULL
Head
254 6 NULLItem
Head
Shashankshetty@nitte.edu.in
2) Insert a node at the End of the list
// Algorithm : Insertion (Item)
// Description : Inserts a node at the End of
the SLL
Step1: Start
Step 2: NewNode=getnode()
NewNode -> link = NULL
NewNode -> info = Item
Step 3: [ If the Linked list is empty, then the
New Node Created is a first node or Head
Node]
if(Head==NULL)
Head=NewNode
return
End if
Step 4: [If the linked list is not empty]
Cur= Head
While (Cur-> link !=NULL)
Cur=Cur->link
end while
Step 5: Cur -> link= NewNode
Step 6: Free(NewNode)
Free (Cur)
Step 5: Return (Stop)
25
Item NULL
NewNode
Head
NULL
4 6 NULL
Head
625 item NULL4
Head
Cur Cur
Shashankshetty@nitte.edu.in
Shashankshetty@nitte.edu.in
3) Insert a node at the middle of two nodes or at
the designated position
// Algorithm : Insertion (Item, position)
// Description : Inserts a node at the middle or at the
designated position of the SLL
Step1: Start
Step 2: NewNode=getnode()
NewNode -> link = NULL
NewNode -> info = Item
Step 3: [ If the Linked list is empty, then the New Node
Created is a first node or Head Node]
if(Head==NULL)
Head=NewNode
return
End if
Step 4: [If the linked list is not empty]
Cur= Head
While (Cur!=position-1)
Cur=Cur->link
end while
Cur1=Cur->link
Step 5: Cur->link= NewNode
NewNode->link= Cur1
Step 6: Free(NewNode)
Free (Cur)
Free(Cur1)
Step 5: Return (Stop)
25
Item NULL
NewNode
Head
NULL
4 6 NULL
Head
625 item NULL4
Head
Cur Cur
1 2 3
Let Us insert
the new
node at
position 3!!!
Cur1
Shashankshetty@nitte.edu.in
Deleting a node from SLL
There are many ways you might want to
delete a new node from a list:
Delete first element
Delete last element
 From the middle of the two nodes or in some
designated position.
Shashankshetty@nitte.edu.in
25
1) Delete a node from the beginning of the list
// Algorithm : Deletion (Item)
// Description : Delete a node from the beginning of
the SLL
Step1: Start
Step 2: [If Empty List]
If (Head==NULL)
Display (“List Empty”)
Return
EndIf
Step 3: [If the linked list is not empty]
Temp=Head
Head=Head-> link
display (temp->info)
Free(Temp)
Step 4: Return (Stop)
Head
NULL
4 6 NULL
Head
25 6 NULL
Head
List
Empty
Temp
Shashankshetty@nitte.edu.in
25
2) Delete a node from the End of the list
// Algorithm : Deletion (Item)
// Description : Delete a node from the end of the
SLL
Step1: Start
Step 2: [If Empty List]
If (Head==NULL)
Display (“List Empty”)
Return
EndIf
Step 3: [If the linked list is not empty]
Temp=Head
While(temp->link!=NULL)
temp1=temp
temp=temp->link
end while
temp1->next=NULL
display (temp->info)
Free(Temp)
Step 4: Return (Stop)
Head
NULL
4 6 NULL
Head
NULL
Temp1
List
Empty
Temp TempTemp1 Temp
NULL
25
Head
4
Shashankshetty@nitte.edu.in
3) Delete a node from the Middle positionor from
specified position
// Algorithm : Deletion (Item, position)
// Description : Delete a node from the
specified position of the SLL
Step1: Start
Step 2: If(Position<=0 or position>length)
Display(“Node position doenot exist”)
EndIf
Step 3: [If Empty List]
If (Head==NULL)
Display (“List Empty”)
Return
EndIf
Step 3: [If the linked list is not empty]
Temp=Head
While(temp !=pos)
temp1=temp
temp=temp->link
end while
temp1->next=temp->next
display (temp->info)
Free(Temp)
Step 4: Return (Stop)

Más contenido relacionado

La actualidad más candente

Linked list
Linked listLinked list
Linked list
VONI
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
Kumar
 

La actualidad más candente (20)

Linked lists 1
Linked lists 1Linked lists 1
Linked lists 1
 
Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)
 
Link list
Link listLink list
Link list
 
Linked List
Linked ListLinked List
Linked List
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
Deletion from single way linked list and search
Deletion from single way linked list and searchDeletion from single way linked list and search
Deletion from single way linked list and search
 
Linked list
Linked listLinked list
Linked list
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
linked list
linked list linked list
linked list
 
Linked lists
Linked listsLinked lists
Linked lists
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
linked list using c
linked list using clinked list using c
linked list using c
 

Destacado

Lecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsLecture 4 data structures and algorithms
Lecture 4 data structures and algorithms
Aakash deep Singhal
 
Bai toan va thuat toan
Bai toan va thuat toanBai toan va thuat toan
Bai toan va thuat toan
Hữu Duy Duy
 

Destacado (20)

Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
 
Linked list
Linked listLinked list
Linked list
 
Linked lists
Linked listsLinked lists
Linked lists
 
U2.linked list
U2.linked listU2.linked list
U2.linked list
 
Ppt of operations on one way link list
Ppt of operations on one way  link listPpt of operations on one way  link list
Ppt of operations on one way link list
 
Lecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsLecture 4 data structures and algorithms
Lecture 4 data structures and algorithms
 
Linked Lists
Linked ListsLinked Lists
Linked Lists
 
Bai toan va thuat toan
Bai toan va thuat toanBai toan va thuat toan
Bai toan va thuat toan
 
Quicksort
QuicksortQuicksort
Quicksort
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Quick sort
Quick sortQuick sort
Quick sort
 
Quick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And AnalysisQuick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And Analysis
 
Quicksort Presentation
Quicksort PresentationQuicksort Presentation
Quicksort Presentation
 
Heap sort
Heap sortHeap sort
Heap sort
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Bài 5: Các thuật toán sắp xếp và tìm kiếm cơ bản - Giáo trình FPT
Bài 5: Các thuật toán sắp xếp và tìm kiếm cơ bản - Giáo trình FPTBài 5: Các thuật toán sắp xếp và tìm kiếm cơ bản - Giáo trình FPT
Bài 5: Các thuật toán sắp xếp và tìm kiếm cơ bản - Giáo trình FPT
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 

Similar a Linked list

Similar a Linked list (20)

Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queues
 
Ds06 linked list- insert a node at beginning
Ds06   linked list- insert a node at beginningDs06   linked list- insert a node at beginning
Ds06 linked list- insert a node at beginning
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
linkrd_list.pdf
linkrd_list.pdflinkrd_list.pdf
linkrd_list.pdf
 
Linked list
Linked list Linked list
Linked list
 
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssssDSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
 
Linked List
Linked ListLinked List
Linked List
 
Ds06 linked list- insert a node at end
Ds06   linked list- insert a node at endDs06   linked list- insert a node at end
Ds06 linked list- insert a node at end
 
Linked list
Linked listLinked list
Linked list
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
Linked list.docx
Linked list.docxLinked list.docx
Linked list.docx
 
Chapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfChapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdf
 
linked list
linked listlinked list
linked list
 
Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptx
 
Link list 2
Link list 2Link list 2
Link list 2
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversal
 
Data Structures_Linked List
Data Structures_Linked ListData Structures_Linked List
Data Structures_Linked List
 

Último

Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 

Linked list

  • 1. LINKED LIST OPERATIONS By, Shashank Shetty Assistant Professor, Department of ISE NMAMIT, Nitte Shashankshetty@nitte.edu.in
  • 2. Inserting a node into a SLL There are many ways you might want to insert a new node into a list: As the new first element As the new last element  In the middle of the two nodes or in some designated position. Shashankshetty@nitte.edu.in
  • 3. 25 1) Insert a node at the beginning of the list // Algorithm : Insertion (Item) // Description : Inserts a node at the beginning of the SLL Step1: Start Step 2: NewNode=getnode() NewNode -> link = NULL NewNode -> info = Item Step 3: [ If the Linked list is empty, then the New Node Created is a first node or Head Node] if(Head==NULL) Head=NewNode return End if Step 4: [If the linked list is not empty] NewNode -> link= Head Head= NewNode Free(NewNode) Step 5: Return (Stop) Item NULL NewNode Head NULL 4 6 NULL Head 254 6 NULLItem Head Shashankshetty@nitte.edu.in
  • 4. 2) Insert a node at the End of the list // Algorithm : Insertion (Item) // Description : Inserts a node at the End of the SLL Step1: Start Step 2: NewNode=getnode() NewNode -> link = NULL NewNode -> info = Item Step 3: [ If the Linked list is empty, then the New Node Created is a first node or Head Node] if(Head==NULL) Head=NewNode return End if Step 4: [If the linked list is not empty] Cur= Head While (Cur-> link !=NULL) Cur=Cur->link end while Step 5: Cur -> link= NewNode Step 6: Free(NewNode) Free (Cur) Step 5: Return (Stop) 25 Item NULL NewNode Head NULL 4 6 NULL Head 625 item NULL4 Head Cur Cur Shashankshetty@nitte.edu.in
  • 5. Shashankshetty@nitte.edu.in 3) Insert a node at the middle of two nodes or at the designated position // Algorithm : Insertion (Item, position) // Description : Inserts a node at the middle or at the designated position of the SLL Step1: Start Step 2: NewNode=getnode() NewNode -> link = NULL NewNode -> info = Item Step 3: [ If the Linked list is empty, then the New Node Created is a first node or Head Node] if(Head==NULL) Head=NewNode return End if Step 4: [If the linked list is not empty] Cur= Head While (Cur!=position-1) Cur=Cur->link end while Cur1=Cur->link Step 5: Cur->link= NewNode NewNode->link= Cur1 Step 6: Free(NewNode) Free (Cur) Free(Cur1) Step 5: Return (Stop) 25 Item NULL NewNode Head NULL 4 6 NULL Head 625 item NULL4 Head Cur Cur 1 2 3 Let Us insert the new node at position 3!!! Cur1
  • 6. Shashankshetty@nitte.edu.in Deleting a node from SLL There are many ways you might want to delete a new node from a list: Delete first element Delete last element  From the middle of the two nodes or in some designated position.
  • 7. Shashankshetty@nitte.edu.in 25 1) Delete a node from the beginning of the list // Algorithm : Deletion (Item) // Description : Delete a node from the beginning of the SLL Step1: Start Step 2: [If Empty List] If (Head==NULL) Display (“List Empty”) Return EndIf Step 3: [If the linked list is not empty] Temp=Head Head=Head-> link display (temp->info) Free(Temp) Step 4: Return (Stop) Head NULL 4 6 NULL Head 25 6 NULL Head List Empty Temp
  • 8. Shashankshetty@nitte.edu.in 25 2) Delete a node from the End of the list // Algorithm : Deletion (Item) // Description : Delete a node from the end of the SLL Step1: Start Step 2: [If Empty List] If (Head==NULL) Display (“List Empty”) Return EndIf Step 3: [If the linked list is not empty] Temp=Head While(temp->link!=NULL) temp1=temp temp=temp->link end while temp1->next=NULL display (temp->info) Free(Temp) Step 4: Return (Stop) Head NULL 4 6 NULL Head NULL Temp1 List Empty Temp TempTemp1 Temp NULL 25 Head 4
  • 9. Shashankshetty@nitte.edu.in 3) Delete a node from the Middle positionor from specified position // Algorithm : Deletion (Item, position) // Description : Delete a node from the specified position of the SLL Step1: Start Step 2: If(Position<=0 or position>length) Display(“Node position doenot exist”) EndIf Step 3: [If Empty List] If (Head==NULL) Display (“List Empty”) Return EndIf Step 3: [If the linked list is not empty] Temp=Head While(temp !=pos) temp1=temp temp=temp->link end while temp1->next=temp->next display (temp->info) Free(Temp) Step 4: Return (Stop)