SlideShare a Scribd company logo
Topic: Deletion from a linked list.
Name: Solaiman Hridoy
Roll: 17010115
Course Title: CSE 211 Data Structure
Batch: 29th (3rd Semester)
Date: 18-03-2018
Deletion from a linked list:
Let us observe fig 1(a) and 1(b) where,
Name of linked list: LIST
No. of nodes: 6
Node A
START
Node N Node B
Node A
START
Node N Node B
Fig.1.(a) Before Deletion
Fig.1.(b) After Deletion
Observe that the deletion occurs as soon as the nextpointer field of node A is changed address so that it
points to node B.
Node A
START
Node N Node B
AVAIL
Free-storage List
Data list
Fig.2
Suppose our linked list is maintained in memory in the form LIST (INFO,
LINK, START, AVAIL)
Figure 1(a) and 1(b) does not take into account the fact that, when a node N
is deleted from our list, we will immediately return its memory space to
the AVAIL list.
In Fig.2 observe that three pointer fields are changed as follows:
1. The nextpointer field of node A now points to be node B, where node N
previously pointed.
2. The nextpointer field of N now points to the original first node in the free
pool, where AVAIL previously pointed.
3. AVAIL now points to the deleted node.
Example
Bed Name Link
01 Krick 7
02 6
03 Dean 11
04 Maxwell 12
05 Adams 3
06 0
07 Lane 4
08 Green 10
09 Samuales 0
10 Jones 1
11 Fields 8
12 Nelson 9
05START
AVAIL 02
Fig.3(a)
Fig.3(b) Before Deletion
START
AVAIL
Free-storage List
Data list
Adams
5
Dean Fields Green Jones Krick Lane Maxwell Nelson Samuels
3 11 8 10 1 7 4 12 9 0
2
6 0
LINK[11]=8
LINK[8]=10
AVAIL=2
0
START
AVAIL
Free-storage List
Data list
Adams
5
Dean Fields Jones Krick Lane Maxwell Nelson Samuels
3 11 10 1 7 4 12 9 0
8
2 6
Fig.3(c) After Deletion
LINK[11]=10
LINK[8]=2
AVAIL=8
Consider Fig.3(a),(b),(c) the list of patients in the hospital ward.
Suppose Green is discharged, so that BED[8] is now empty. Then, in
order to maintain the linked list, the following three changes in the
pointer fields must be executed:
LINK[11]=10 LINK[8]=2 AVAIL=8
Deleting the Node Following a Given Node
LOC= Location of N
LOCP= the node preceding N
Algorithm: DEL (INFO, LINK, START, AVAIL, LOC, LOCP)
This algorithm deletes the node N with location LOC. LOCP is the location of the node which
precedes N or when N is the first node, LOCP=NULL.
1. If LOCP=NULL then:
Set Start = LINK [START]. [Deletes the first node N]
Else:
Set LINK [LOCP] = LINK [LOC]. [Deletes node N]
[End of If structure]
2. [Return deleted node to the AVAIL list]
Set LINK[LOC] = AVAIL and AVAIL = LOC
3. Exit.
Node 1
START
Node 2 Node 3
START = LINK [START]
Fig 4(a) : Deleting the first node from the list. This covers the case when N is the first node.
START LOCP LOC
Node N
LINK [LOCP] = LINK [LOC]
Fig 4(b): Deleting the node N when N is not the first node.
Deleting the Node with a Given ITEM of Information
First we give a procedure which finds the location LOC of the node preceding N containing
ITEM and the location LOCP of the node preceding node N.
Procedure: FINDB (INFO, LINK, START, ITEM, LOC, LOCP)
1. [List empty?] If START = NULL, then:
Set LOC = NULL and LOCP = NULL and Return. [End of If structure]
2. [ITEM in first node?] If INFO[START] = ITEM, then:
Set LOC = START and LOCP = NULL and Return.
[End of IF structure]
3. Set SAVE = START and PTR = LINK [START]. [Initializes pointers]
4.Repeat steps 5 and 6 while PTR != NULL.
5. If INFO[PTR] = ITEM, then:
Set LOC = PTR and LOCP = SAVE, and Return. [End of IF structure]
6. Set SAVE = PTR and PTR = LINK[PTR] [Updates pointers] [End of Step 4 loop]
7. Set LOC = NULL [Search unsuccessful]
8. Return.
To delete the node of the given item of information observe the algorithm:
Algorithm: DELETE (INFO, LINK, START, AVAIL, ITEM)
1. [Use Procedure 5.9 to find the location of N and its preceding node]
Call FINDB (INFO, LINK, START, ITEM, LOC, LOCP)
2. If LOC = NULL, then: Write: ITEM not in list, and Exit.
3. [Delete node]
If LOCP = NULL, then:
Set START = LINK [START]. [Deletes first node]
Else:
Set LINK [LOCP] = LINK [LOC]
[End of If structure]
4. [Return deleted node to the AVAIL list]
Set LINK [LOC] = AVAIL and AVAIL = LOC.
5. Exit.
Example:
Bed Name Link
01 Krick 7
02 6
03 Dean 11
04 Maxwell 12
05 Adams 3
06 0
07 Lane 4
08 Green 10
09 Samuales 0
10 Jones 1
11 Fields 8
12 Nelson 9
05START
AVAIL 02
ITEM = Green
INFO = BED
START = 5
AVAIL = 2
ITEM = Green
Fig.5(a)
Fig.5(b): Finding the location of item of information
START
AVAIL
Free-storage List
Data list
Adams
5
Dean Fields Green Jones Krick Lane Maxwell Nelson Samuels
3 11 8 10 1 7 4 12 9 0
2
6 0
FINDB(BED, LINK, STAT, ITEM, LOC, LOCP)
1. Since START != NULL, control is transferred to Step 2.
2. Since BED[5] = Adams != Green, control is transferred to Step 3.
3. SAVE = 5 and PTR = LINK[5]=3.
4. Steps 5 and 6 are repeated as follows:
(a) BED[3] = Dean != Green, so
SAVE = 3 and PTR = LINK[3] = 11.
(b) BED[11] = Fields != Green, so
SAVE = 11 and PTR = LINK[11] = 8.
(c) BED[8] = Green, so we have:
LOC = PTR = 8 and LOCP = SAVE = 11, and Return.
0
START
AVAIL
Free-storage List
Data list
Adams
5
Dean Fields Jones Krick Lane Maxwell Nelson Samuels
3 11 10 1 7 4 12 9 0
8
2 6
Fig.5(c) Deleting the node of the given item
DELETE(BED, LINK, START, AVAIL, ITEM)
1. Call FINDB(BED, LINK, START, AVAIL, ITEM)
2. Since LOC != NULL, control is transferred to step 3.
3. Since LOCP != NULL, we have:
LINK[11] = LINK[8] = 10.
4.LINK[8] = 2 and AVAIL = 8.
5. Exit.

More Related Content

Similar to Deletion from a linked list

ds 2Arrays.ppt
ds 2Arrays.pptds 2Arrays.ppt
ds 2Arrays.ppt
AlliVinay1
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms Arrays
ManishPrajapati78
 
Module 3 Dara structure notes
Module 3 Dara structure notesModule 3 Dara structure notes
Module 3 Dara structure notes
Dreamers6
 
Array 2
Array 2Array 2
Array 2
Abbott
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
AlliVinay1
 
Data structures Lecture no.6
Data structures Lecture no.6Data structures Lecture no.6
Data structures Lecture no.6
AzharIqbal710687
 
Chapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfChapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdf
Axmedcarb
 
unit 2- PPT.pdf
unit 2- PPT.pdfunit 2- PPT.pdf
unit 2- PPT.pdf
PranavMakwana6
 
Bcsl 033 solve assignment
Bcsl 033 solve assignmentBcsl 033 solve assignment
4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)
Chandan Singh
 
LEC3-DS ALGO(updated).pdf
LEC3-DS  ALGO(updated).pdfLEC3-DS  ALGO(updated).pdf
LEC3-DS ALGO(updated).pdf
MuhammadUmerIhtisham
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
Mandeep Singh
 
Two Dimensional Array
Two Dimensional ArrayTwo Dimensional Array
Two Dimensional Array
dincyjain
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
Sowmya Jyothi
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ManishPrajapati78
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithms
Aakash deep Singhal
 
Lect 11-12 Zaheer Abbas
Lect 11-12 Zaheer AbbasLect 11-12 Zaheer Abbas
Lect 11-12 Zaheer Abbas
Information Technology Center
 
Stack data structure
Stack data structureStack data structure
Stack data structure
Soumyajit Pal
 
Updated Lab3.docx
Updated Lab3.docxUpdated Lab3.docx
Updated Lab3.docx
AleezaAnjum
 
Lecture 7 data structures and algorithms
Lecture 7 data structures and algorithmsLecture 7 data structures and algorithms
Lecture 7 data structures and algorithms
Aakash deep Singhal
 

Similar to Deletion from a linked list (20)

ds 2Arrays.ppt
ds 2Arrays.pptds 2Arrays.ppt
ds 2Arrays.ppt
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms Arrays
 
Module 3 Dara structure notes
Module 3 Dara structure notesModule 3 Dara structure notes
Module 3 Dara structure notes
 
Array 2
Array 2Array 2
Array 2
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
 
Data structures Lecture no.6
Data structures Lecture no.6Data structures Lecture no.6
Data structures Lecture no.6
 
Chapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfChapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdf
 
unit 2- PPT.pdf
unit 2- PPT.pdfunit 2- PPT.pdf
unit 2- PPT.pdf
 
Bcsl 033 solve assignment
Bcsl 033 solve assignmentBcsl 033 solve assignment
Bcsl 033 solve assignment
 
4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)
 
LEC3-DS ALGO(updated).pdf
LEC3-DS  ALGO(updated).pdfLEC3-DS  ALGO(updated).pdf
LEC3-DS ALGO(updated).pdf
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
 
Two Dimensional Array
Two Dimensional ArrayTwo Dimensional Array
Two Dimensional Array
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithms
 
Lect 11-12 Zaheer Abbas
Lect 11-12 Zaheer AbbasLect 11-12 Zaheer Abbas
Lect 11-12 Zaheer Abbas
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Updated Lab3.docx
Updated Lab3.docxUpdated Lab3.docx
Updated Lab3.docx
 
Lecture 7 data structures and algorithms
Lecture 7 data structures and algorithmsLecture 7 data structures and algorithms
Lecture 7 data structures and algorithms
 

Recently uploaded

Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 

Deletion from a linked list

  • 1. Topic: Deletion from a linked list. Name: Solaiman Hridoy Roll: 17010115 Course Title: CSE 211 Data Structure Batch: 29th (3rd Semester) Date: 18-03-2018
  • 2. Deletion from a linked list: Let us observe fig 1(a) and 1(b) where, Name of linked list: LIST No. of nodes: 6 Node A START Node N Node B Node A START Node N Node B Fig.1.(a) Before Deletion Fig.1.(b) After Deletion Observe that the deletion occurs as soon as the nextpointer field of node A is changed address so that it points to node B.
  • 3. Node A START Node N Node B AVAIL Free-storage List Data list Fig.2
  • 4. Suppose our linked list is maintained in memory in the form LIST (INFO, LINK, START, AVAIL) Figure 1(a) and 1(b) does not take into account the fact that, when a node N is deleted from our list, we will immediately return its memory space to the AVAIL list. In Fig.2 observe that three pointer fields are changed as follows: 1. The nextpointer field of node A now points to be node B, where node N previously pointed. 2. The nextpointer field of N now points to the original first node in the free pool, where AVAIL previously pointed. 3. AVAIL now points to the deleted node.
  • 5. Example Bed Name Link 01 Krick 7 02 6 03 Dean 11 04 Maxwell 12 05 Adams 3 06 0 07 Lane 4 08 Green 10 09 Samuales 0 10 Jones 1 11 Fields 8 12 Nelson 9 05START AVAIL 02 Fig.3(a)
  • 6. Fig.3(b) Before Deletion START AVAIL Free-storage List Data list Adams 5 Dean Fields Green Jones Krick Lane Maxwell Nelson Samuels 3 11 8 10 1 7 4 12 9 0 2 6 0 LINK[11]=8 LINK[8]=10 AVAIL=2
  • 7. 0 START AVAIL Free-storage List Data list Adams 5 Dean Fields Jones Krick Lane Maxwell Nelson Samuels 3 11 10 1 7 4 12 9 0 8 2 6 Fig.3(c) After Deletion LINK[11]=10 LINK[8]=2 AVAIL=8
  • 8. Consider Fig.3(a),(b),(c) the list of patients in the hospital ward. Suppose Green is discharged, so that BED[8] is now empty. Then, in order to maintain the linked list, the following three changes in the pointer fields must be executed: LINK[11]=10 LINK[8]=2 AVAIL=8
  • 9. Deleting the Node Following a Given Node LOC= Location of N LOCP= the node preceding N Algorithm: DEL (INFO, LINK, START, AVAIL, LOC, LOCP) This algorithm deletes the node N with location LOC. LOCP is the location of the node which precedes N or when N is the first node, LOCP=NULL. 1. If LOCP=NULL then: Set Start = LINK [START]. [Deletes the first node N] Else: Set LINK [LOCP] = LINK [LOC]. [Deletes node N] [End of If structure] 2. [Return deleted node to the AVAIL list] Set LINK[LOC] = AVAIL and AVAIL = LOC 3. Exit.
  • 10. Node 1 START Node 2 Node 3 START = LINK [START] Fig 4(a) : Deleting the first node from the list. This covers the case when N is the first node. START LOCP LOC Node N LINK [LOCP] = LINK [LOC] Fig 4(b): Deleting the node N when N is not the first node.
  • 11. Deleting the Node with a Given ITEM of Information First we give a procedure which finds the location LOC of the node preceding N containing ITEM and the location LOCP of the node preceding node N. Procedure: FINDB (INFO, LINK, START, ITEM, LOC, LOCP) 1. [List empty?] If START = NULL, then: Set LOC = NULL and LOCP = NULL and Return. [End of If structure] 2. [ITEM in first node?] If INFO[START] = ITEM, then: Set LOC = START and LOCP = NULL and Return. [End of IF structure] 3. Set SAVE = START and PTR = LINK [START]. [Initializes pointers] 4.Repeat steps 5 and 6 while PTR != NULL. 5. If INFO[PTR] = ITEM, then: Set LOC = PTR and LOCP = SAVE, and Return. [End of IF structure] 6. Set SAVE = PTR and PTR = LINK[PTR] [Updates pointers] [End of Step 4 loop] 7. Set LOC = NULL [Search unsuccessful] 8. Return.
  • 12. To delete the node of the given item of information observe the algorithm: Algorithm: DELETE (INFO, LINK, START, AVAIL, ITEM) 1. [Use Procedure 5.9 to find the location of N and its preceding node] Call FINDB (INFO, LINK, START, ITEM, LOC, LOCP) 2. If LOC = NULL, then: Write: ITEM not in list, and Exit. 3. [Delete node] If LOCP = NULL, then: Set START = LINK [START]. [Deletes first node] Else: Set LINK [LOCP] = LINK [LOC] [End of If structure] 4. [Return deleted node to the AVAIL list] Set LINK [LOC] = AVAIL and AVAIL = LOC. 5. Exit.
  • 13. Example: Bed Name Link 01 Krick 7 02 6 03 Dean 11 04 Maxwell 12 05 Adams 3 06 0 07 Lane 4 08 Green 10 09 Samuales 0 10 Jones 1 11 Fields 8 12 Nelson 9 05START AVAIL 02 ITEM = Green INFO = BED START = 5 AVAIL = 2 ITEM = Green Fig.5(a)
  • 14. Fig.5(b): Finding the location of item of information START AVAIL Free-storage List Data list Adams 5 Dean Fields Green Jones Krick Lane Maxwell Nelson Samuels 3 11 8 10 1 7 4 12 9 0 2 6 0 FINDB(BED, LINK, STAT, ITEM, LOC, LOCP) 1. Since START != NULL, control is transferred to Step 2. 2. Since BED[5] = Adams != Green, control is transferred to Step 3. 3. SAVE = 5 and PTR = LINK[5]=3. 4. Steps 5 and 6 are repeated as follows: (a) BED[3] = Dean != Green, so SAVE = 3 and PTR = LINK[3] = 11. (b) BED[11] = Fields != Green, so SAVE = 11 and PTR = LINK[11] = 8. (c) BED[8] = Green, so we have: LOC = PTR = 8 and LOCP = SAVE = 11, and Return.
  • 15. 0 START AVAIL Free-storage List Data list Adams 5 Dean Fields Jones Krick Lane Maxwell Nelson Samuels 3 11 10 1 7 4 12 9 0 8 2 6 Fig.5(c) Deleting the node of the given item DELETE(BED, LINK, START, AVAIL, ITEM) 1. Call FINDB(BED, LINK, START, AVAIL, ITEM) 2. Since LOC != NULL, control is transferred to step 3. 3. Since LOCP != NULL, we have: LINK[11] = LINK[8] = 10. 4.LINK[8] = 2 and AVAIL = 8. 5. Exit.