SlideShare uma empresa Scribd logo
1 de 15
Linked List
By
Nilesh Dalvi
Lecturer, Patkar-Varde College.Lecturer, Patkar-Varde College.
http://www.slideshare.net/nileshdalvi01
Java and DataJava and Data
StructuresStructures
Linked List
• Linear collection of data elements called
nodes.
• Linear order is given by means of pointers.
• Each node is divided into two parts, first part
contains info and second part, called link.
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
NULLNULL
Start Node A Node B Node C End
10 20 30 40
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Representation of Linked List
• Let LIST be a linked list,
• LIST requires two linear array:
– INFO[k] – information part
– LINK [k] – next pointer field
• Also requires variable Name – such as START-
which contains the location of the beginning
of the list
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Representation of Linked List
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
O
J
L
W
N
START
1
2
3
4
5
6
7
8
9
10
6
7
5
3
INFO LINK
9 START 9 INFO[9] N
LINK[9] 3 INFO[3] O
LINK[3] 6 INFO[6] L
LINK[6] 5 INFO[5] J
LINK[5] 7 INFO[7] W
Traversing a Linked List
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
NULLNULL
Start
Node A Node B Node C End
20 30 4010
PTR
Algorithm TraverseList(INFO, LINK, START)
{
PTR := START;
while (PTR != NULL)
{
Process --> INFO[PTR];
PTR := LINK[PTR];
}
}
Traversing a Linked List
• Write algorithm to
– Print elements
– Count elements
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Searching a Linked List
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm SearchList(INFO, LINK, START, ITEM)
{
PTR := START;
while (PTR != NULL)
{
if (ITEM = INFO[PTR])THEN
LOC := PTR;
else
PTR := LINK[PTR];
}
}
Insertion into Linked List:@beginning
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm InsertFirst(INFO, LINK, START, AVAIL, ITEM)
{
if(AVAIL = NULL) THEN
write("Overflow!");
else
NEW := AVAIL;
AVAIL := LINK [AVAIL];
INFO[NEW] := ITEM;
LINK[NEW]:=START;
START:=NEW;
}
NULLNULL
Start
Node A Node B Node C End
20 30 4010
NULLNULL
AVAIL
NEW 50
Inserting after a given node
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm InsertAtLoc(INFO, LINK, START, AVAIL, LOC, ITEM)
{
if(AVAIL = NULL)
write("Overflow");
else
NEW := AVAIL;
AVAIL := LINK [AVAIL];
INFO [NEW] := ITEM;
if(LOC = NULL) then
{
LINK [NEW] := START;
START := NEW;
}
else
{
LINK [NEW] := LINK[LOC];
LINK[LOC] :=NEW;
}
}
Inserting @end
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm InsertAtEnd(INFO, LINK, START, AVAIL, ITEM)
{
if(AVAIL = NULL)
write("Overflow");
else
NEW := AVAIL;
AVAIL := LINK [AVAIL];
INFO [NEW] := ITEM;
PTR := START;
while (LINK[PTR] != NULL)
{
PTR := LINK[PTR];
}
LINK [PTR] := NEW;
}
Deleting first node
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm DeleteFirst(INFO, LINK, START, AVAIL)
{
PTR := LINK [START];
if(PTR = NULL)
write("Underflow!");
else
PTR1 := LINK [PTR];
LINK [START] := PTR1;
//Returns deleted node to the AVAIL list.
LINK [PTR] := AVAIL;
AVAIL := PTR;
}
NULLNULL
Start
Node A Node B Node C End
20 30 4010
NULLNULL
AVAIL
PTR PTR1
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Deleting End node
Algorithm DeleteEnd(INFO, LINK, START, AVAIL)
{
PTR := START;
if(LINK[PTR] = NULL)
write("Underflow!");
else
while(LINK [PTR]!=NULL)
{
PTR1 := PTR;
PTR := LINK [PTR];
}
LINK [PTR1] := NULL;
//Returns deleted node to the AVAIL list.
LINK [PTR] := AVAIL;
AVAIL := PTR;
}
NULLNULL
Start
Node A Node B Node C End
20 30 4010
NULLNULL
AVAIL
PTR PTR1
NULL
Deleting specific node
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Algorithm DeleteSpecific(INFO, LINK, START, AVAIL, KEY)
{
PTR1 := START;
PTR := LINK [PTR1];
while(PTR != NULL)
{
if (INFO [PTR] != KEY) then
{
PTR1 := PTR;
PTR := LINK[PTR];
}
else
{
LINK [PTR1] := LINK [PTR];
}
//Returns deleted node to the AVAIL list.
LINK [PTR] := AVAIL;
AVAIL := PTR;
}
if(PTR = NULL)then
write("NODE with KEY does not exist");
}
Applications
• Polynomial Representation
– Polynomial having single variable is,
Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
Q & A

Mais conteúdo relacionado

Mais procurados

02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory MappingQundeel
 
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT LATHA LAKSHMI
 
Array 2
Array 2Array 2
Array 2Abbott
 
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van HovellAn Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van HovellDatabricks
 
Spark Schema For Free with David Szakallas
 Spark Schema For Free with David Szakallas Spark Schema For Free with David Szakallas
Spark Schema For Free with David SzakallasDatabricks
 
Spark schema for free with David Szakallas
Spark schema for free with David SzakallasSpark schema for free with David Szakallas
Spark schema for free with David SzakallasDatabricks
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structuresMohd Arif
 
Lecture 1 Introduction C++
Lecture 1 Introduction C++Lecture 1 Introduction C++
Lecture 1 Introduction C++Ajay Khatri
 
JS Responsibilities
JS ResponsibilitiesJS Responsibilities
JS ResponsibilitiesBrendan Eich
 
08 class and object
08   class and object08   class and object
08 class and objectdhrubo kayal
 

Mais procurados (16)

Vectors,squence & list
Vectors,squence & listVectors,squence & list
Vectors,squence & list
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
 
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
 
Array 2
Array 2Array 2
Array 2
 
Arrays
ArraysArrays
Arrays
 
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van HovellAn Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
 
Spark Schema For Free with David Szakallas
 Spark Schema For Free with David Szakallas Spark Schema For Free with David Szakallas
Spark Schema For Free with David Szakallas
 
Spark schema for free with David Szakallas
Spark schema for free with David SzakallasSpark schema for free with David Szakallas
Spark schema for free with David Szakallas
 
Priority queues
Priority queuesPriority queues
Priority queues
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structures
 
Property Based Tesing
Property Based TesingProperty Based Tesing
Property Based Tesing
 
Lecture 1 Introduction C++
Lecture 1 Introduction C++Lecture 1 Introduction C++
Lecture 1 Introduction C++
 
Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]
 
JS Responsibilities
JS ResponsibilitiesJS Responsibilities
JS Responsibilities
 
08 class and object
08   class and object08   class and object
08 class and object
 
Algorithm
AlgorithmAlgorithm
Algorithm
 

Destaque

Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops conceptsNilesh Dalvi
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++Nilesh Dalvi
 
Ch04 Linked List Structure
Ch04 Linked List StructureCh04 Linked List Structure
Ch04 Linked List Structureleminhvuong
 
6. Exception Handling
6. Exception Handling6. Exception Handling
6. Exception HandlingNilesh Dalvi
 
5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and IntefacesNilesh Dalvi
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cppNilesh Dalvi
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++Amresh Raj
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending ClassesNilesh Dalvi
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and VariablesNilesh Dalvi
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in javaNilesh Dalvi
 
class and objects
class and objectsclass and objects
class and objectsPayel Guria
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).pptAlok Kumar
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructorsNilesh Dalvi
 

Destaque (20)

7. Multithreading
7. Multithreading7. Multithreading
7. Multithreading
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
Ch04 Linked List Structure
Ch04 Linked List StructureCh04 Linked List Structure
Ch04 Linked List Structure
 
8. String
8. String8. String
8. String
 
6. Exception Handling
6. Exception Handling6. Exception Handling
6. Exception Handling
 
5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending Classes
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and Variables
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Strings
StringsStrings
Strings
 
class and objects
class and objectsclass and objects
class and objects
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
 
File handling
File handlingFile handling
File handling
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 

Último

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
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
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 

Último (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 

14. Linked List

  • 1. Linked List By Nilesh Dalvi Lecturer, Patkar-Varde College.Lecturer, Patkar-Varde College. http://www.slideshare.net/nileshdalvi01 Java and DataJava and Data StructuresStructures
  • 2. Linked List • Linear collection of data elements called nodes. • Linear order is given by means of pointers. • Each node is divided into two parts, first part contains info and second part, called link. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). NULLNULL Start Node A Node B Node C End 10 20 30 40 Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 3. Representation of Linked List • Let LIST be a linked list, • LIST requires two linear array: – INFO[k] – information part – LINK [k] – next pointer field • Also requires variable Name – such as START- which contains the location of the beginning of the list Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 4. Representation of Linked List Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). O J L W N START 1 2 3 4 5 6 7 8 9 10 6 7 5 3 INFO LINK 9 START 9 INFO[9] N LINK[9] 3 INFO[3] O LINK[3] 6 INFO[6] L LINK[6] 5 INFO[5] J LINK[5] 7 INFO[7] W
  • 5. Traversing a Linked List Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). NULLNULL Start Node A Node B Node C End 20 30 4010 PTR Algorithm TraverseList(INFO, LINK, START) { PTR := START; while (PTR != NULL) { Process --> INFO[PTR]; PTR := LINK[PTR]; } }
  • 6. Traversing a Linked List • Write algorithm to – Print elements – Count elements Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 7. Searching a Linked List Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm SearchList(INFO, LINK, START, ITEM) { PTR := START; while (PTR != NULL) { if (ITEM = INFO[PTR])THEN LOC := PTR; else PTR := LINK[PTR]; } }
  • 8. Insertion into Linked List:@beginning Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm InsertFirst(INFO, LINK, START, AVAIL, ITEM) { if(AVAIL = NULL) THEN write("Overflow!"); else NEW := AVAIL; AVAIL := LINK [AVAIL]; INFO[NEW] := ITEM; LINK[NEW]:=START; START:=NEW; } NULLNULL Start Node A Node B Node C End 20 30 4010 NULLNULL AVAIL NEW 50
  • 9. Inserting after a given node Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm InsertAtLoc(INFO, LINK, START, AVAIL, LOC, ITEM) { if(AVAIL = NULL) write("Overflow"); else NEW := AVAIL; AVAIL := LINK [AVAIL]; INFO [NEW] := ITEM; if(LOC = NULL) then { LINK [NEW] := START; START := NEW; } else { LINK [NEW] := LINK[LOC]; LINK[LOC] :=NEW; } }
  • 10. Inserting @end Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm InsertAtEnd(INFO, LINK, START, AVAIL, ITEM) { if(AVAIL = NULL) write("Overflow"); else NEW := AVAIL; AVAIL := LINK [AVAIL]; INFO [NEW] := ITEM; PTR := START; while (LINK[PTR] != NULL) { PTR := LINK[PTR]; } LINK [PTR] := NEW; }
  • 11. Deleting first node Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm DeleteFirst(INFO, LINK, START, AVAIL) { PTR := LINK [START]; if(PTR = NULL) write("Underflow!"); else PTR1 := LINK [PTR]; LINK [START] := PTR1; //Returns deleted node to the AVAIL list. LINK [PTR] := AVAIL; AVAIL := PTR; } NULLNULL Start Node A Node B Node C End 20 30 4010 NULLNULL AVAIL PTR PTR1
  • 12. Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Deleting End node Algorithm DeleteEnd(INFO, LINK, START, AVAIL) { PTR := START; if(LINK[PTR] = NULL) write("Underflow!"); else while(LINK [PTR]!=NULL) { PTR1 := PTR; PTR := LINK [PTR]; } LINK [PTR1] := NULL; //Returns deleted node to the AVAIL list. LINK [PTR] := AVAIL; AVAIL := PTR; } NULLNULL Start Node A Node B Node C End 20 30 4010 NULLNULL AVAIL PTR PTR1 NULL
  • 13. Deleting specific node Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W). Algorithm DeleteSpecific(INFO, LINK, START, AVAIL, KEY) { PTR1 := START; PTR := LINK [PTR1]; while(PTR != NULL) { if (INFO [PTR] != KEY) then { PTR1 := PTR; PTR := LINK[PTR]; } else { LINK [PTR1] := LINK [PTR]; } //Returns deleted node to the AVAIL list. LINK [PTR] := AVAIL; AVAIL := PTR; } if(PTR = NULL)then write("NODE with KEY does not exist"); }
  • 14. Applications • Polynomial Representation – Polynomial having single variable is, Nilesh Dalvi, Lecturer@Patkar-Varde College, Goregaon(W).
  • 15. Q & A