SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Kürzlich hochgeladen

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 

Kürzlich hochgeladen (20)

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.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