SlideShare a Scribd company logo
1 of 15
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.pptAlliVinay1
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms ArraysManishPrajapati78
 
Module 3 Dara structure notes
Module 3 Dara structure notesModule 3 Dara structure notes
Module 3 Dara structure notesDreamers6
 
Array 2
Array 2Array 2
Array 2Abbott
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.pptAlliVinay1
 
Data structures Lecture no.6
Data structures Lecture no.6Data structures Lecture no.6
Data structures Lecture no.6AzharIqbal710687
 
Chapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfChapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfAxmedcarb
 
4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)Chandan Singh
 
Two Dimensional Array
Two Dimensional ArrayTwo Dimensional Array
Two Dimensional Arraydincyjain
 
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 jyothiSowmya Jyothi
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListManishPrajapati78
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsAakash deep Singhal
 
Stack data structure
Stack data structureStack data structure
Stack data structureSoumyajit Pal
 
Updated Lab3.docx
Updated Lab3.docxUpdated Lab3.docx
Updated Lab3.docxAleezaAnjum
 
Lecture 7 data structures and algorithms
Lecture 7 data structures and algorithmsLecture 7 data structures and algorithms
Lecture 7 data structures and algorithmsAakash 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

diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhleson0603
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 

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.