SlideShare a Scribd company logo
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

More Related Content

What's hot

Vectors,squence & list
Vectors,squence & listVectors,squence & list
Vectors,squence & list
Monika Sanghani
 
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 2
Abbott
 
Arrays
ArraysArrays
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
Databricks
 
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
Databricks
 
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
Databricks
 
Priority queues
Priority queuesPriority queues
Priority queues
Yeela Mehroz
 
Arrays and structures
Arrays and structuresArrays and structures
Arrays and structuresMohd Arif
 
Property Based Tesing
Property Based TesingProperty Based Tesing
Property Based Tesing
Mårten Rånge
 
Lecture 1 Introduction C++
Lecture 1 Introduction C++Lecture 1 Introduction C++
Lecture 1 Introduction C++
Ajay Khatri
 
Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]
Muhammad Hammad Waseem
 
JS Responsibilities
JS ResponsibilitiesJS Responsibilities
JS Responsibilities
Brendan Eich
 
08 class and object
08   class and object08   class and object
08 class and objectdhrubo kayal
 

What's hot (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
 

Viewers also liked

7. Multithreading
7. Multithreading7. Multithreading
7. Multithreading
Nilesh Dalvi
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Nilesh Dalvi
 
Introduction to oops concepts
Introduction to oops conceptsIntroduction to oops concepts
Introduction to oops concepts
Nilesh 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
 
8. String
8. String8. String
8. String
Nilesh Dalvi
 
6. Exception Handling
6. Exception Handling6. Exception Handling
6. Exception Handling
Nilesh Dalvi
 
5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces5. Inheritances, Packages and Intefaces
5. Inheritances, Packages and Intefaces
Nilesh Dalvi
 
Introduction to cpp
Introduction to cppIntroduction to cpp
Introduction to cpp
Nilesh 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 Classes
Nilesh Dalvi
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and Variables
Nilesh Dalvi
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
Nilesh Dalvi
 
Strings
StringsStrings
Strings
Nilesh Dalvi
 
class and objects
class and objectsclass and objects
class and objectsPayel Guria
 
File handling
File handlingFile handling
File handling
Nilesh Dalvi
 
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 destructors
Nilesh Dalvi
 

Viewers also liked (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
 

Recently uploaded

Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 

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