SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
Linked List
Abhishek H Menon
abhishekmenon@gmail.com
www.facebook.com/abhishe
kmenon5
twitter.com/abhishekmenon
121989
in.linkedin.com/in/Abhishek
H Menon
9496519895
Linked List
• Consists of
– Sequence of nodes.
Each node contains a value and a link to some other
node.(pointer or reference)
The last node will be having a link which points to
null.
The list may or may not have a header.
Linked Lists
a b c d
Structure of a Linked List
List(Header)
Linked List
• Successor :successor of a node is the node
pointing next to that node.(suc(a)=b).
• Predecessor: predecessor of a node is the
node pointing this node.(pre(b)=a).
• The length of the linked list is the number of
nodes in it.
Linked Lists
• In programming languages like C,CPP we are
using “pointers ” to implement linked lists.
• But in java programming, we use references
instead of pointers.
• To some extent both are same , but the
difference is that C and CPP allows to modify
pointers in anyways, and can point to
anything.
Creating references
• Person p=new Person(“John”);
the keyword ‘new’ creates the object and
returns a references.
here new Person(“John”) creates the object
and returns a references to it.
We can assign this reference to P.
Creating links
A B C D
Class node
{
node next;
char value;
Node(char value, node n) //constructor
{
value=value;
next=n;
}
}
Creating Links
• Node temp=new node(D, null);
• temp=new node(C,temp);
• temp=new node(B,temp);
• temp=new node(A,temp);
• Temp=new node(null,temp);
Single linked list
• Each node will have a value and a link to the
next value(successor).
• There will be a header which points either to
the first element of the list, or if the list is
empty it will point to the null link.
Singly Linked Lists(SLL)
A B C D
Traversing a SLL
• The following method traverses a list and print
its elements.
public void printFirstToLast(Node here) {
while (here != null) {
System.out.print(here.value + " ");
here = here.next;
}
}
You would write this as an instance method of the Node class.
Singly Linked Lists(SLL)
A B C D
header
here
Inserting an element into a list
• There are many ways to insert an element into
a singly linked list.
– As the new first element
– As the new last element
– Before a given node
– After a given node
– Before a given value
– After a given value
Inserting as a new first element
• The easiest method to implement
• In class Node
Node insertAtFront(Node oldFront, Object value) {
Node newNode = new Node(value, oldFront);
return newNode;
}
Use this as: myList = insertAtFront(myList, value);
Insert node after a given value
void insertAfter(Object target, Object value) {
for (Node here = this; here != null; here = here.next) {
if (here.value.equals(target)) {
Node node = new Node(value, here.next);
here.next = node;
return;
}
}
// Couldn't insert--do something reasonable here!
}
Deleting a node from a SLL
• In order to delete a node from a SLL, you have
to change the link in its predecessor
• This is slightly tricky, because you can’t follow
a pointer backwards
• Deleting the first node in a list is a special
case, because the node’s predecessor is the
list header
Deleting a node from a SLL
A B C
header
To delete the first element, change the link in the header.
Deleting an element from a SLL
• To delete some other element, change the link
in its predecessor.
A B C
predecessor
Doubly linked lists
Doubly Linked List
Each node contain a pointer to the successor and a pointer to its
predecessor.
Header points to the first element in the list and last element
A B C
Advantages and disadvantages of DLL
over SLL
• Advantages
– Can be traversed in either direction.
– Such operations such as insertion deletion
becomes much easier when compared to SLL.
• Disadvantages
 Requires more space.
 List manipulations are slower because more links are
changed
 Greater chance of having bugs.
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emerald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Ernakulam,
Kerala, India.
Email: info@baabtra.com

Weitere ähnliche Inhalte

Was ist angesagt?

DBMS - Relational Algebra
DBMS - Relational AlgebraDBMS - Relational Algebra
DBMS - Relational AlgebraMythiliMurugan3
 
9781285852744 ppt ch08
9781285852744 ppt ch089781285852744 ppt ch08
9781285852744 ppt ch08Terry Yoast
 
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHIBCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHISowmya Jyothi
 
Programming Languages - Functional Programming Paper
Programming Languages - Functional Programming PaperProgramming Languages - Functional Programming Paper
Programming Languages - Functional Programming PaperShreya Chakrabarti
 
Flex (fast lexical analyzer generator )
Flex (fast lexical analyzer generator )Flex (fast lexical analyzer generator )
Flex (fast lexical analyzer generator )Sandip Basnet
 
Introduction to lambda calculus
Introduction to lambda calculusIntroduction to lambda calculus
Introduction to lambda calculusAfaq Siddiqui
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lexAnusuya123
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1sumitbardhan
 
9781285852744 ppt ch12
9781285852744 ppt ch129781285852744 ppt ch12
9781285852744 ppt ch12Terry Yoast
 
R Programming: Introduction to Vectors
R Programming: Introduction to VectorsR Programming: Introduction to Vectors
R Programming: Introduction to VectorsRsquared Academy
 
Unit iv-syntax-directed-translation
Unit iv-syntax-directed-translationUnit iv-syntax-directed-translation
Unit iv-syntax-directed-translationAjith kumar M P
 

Was ist angesagt? (20)

DBMS - Relational Algebra
DBMS - Relational AlgebraDBMS - Relational Algebra
DBMS - Relational Algebra
 
9781285852744 ppt ch08
9781285852744 ppt ch089781285852744 ppt ch08
9781285852744 ppt ch08
 
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHIBCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
BCA DATA STRUCTURES ALGORITHMS AND PRELIMINARIES MRS SOWMYA JYOTHI
 
Programming Languages - Functional Programming Paper
Programming Languages - Functional Programming PaperProgramming Languages - Functional Programming Paper
Programming Languages - Functional Programming Paper
 
Flex (fast lexical analyzer generator )
Flex (fast lexical analyzer generator )Flex (fast lexical analyzer generator )
Flex (fast lexical analyzer generator )
 
Introduction to lambda calculus
Introduction to lambda calculusIntroduction to lambda calculus
Introduction to lambda calculus
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1
 
Lex Tool
Lex ToolLex Tool
Lex Tool
 
Bottom up parser
Bottom up parserBottom up parser
Bottom up parser
 
9781285852744 ppt ch12
9781285852744 ppt ch129781285852744 ppt ch12
9781285852744 ppt ch12
 
Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)Parsing LL(1), SLR, LR(1)
Parsing LL(1), SLR, LR(1)
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational Algebra
 
R Course Online
R Course OnlineR Course Online
R Course Online
 
Optimization of dfa
Optimization of dfaOptimization of dfa
Optimization of dfa
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
 
R Programming: Introduction to Vectors
R Programming: Introduction to VectorsR Programming: Introduction to Vectors
R Programming: Introduction to Vectors
 
Chapter6
Chapter6Chapter6
Chapter6
 
Typeclass
TypeclassTypeclass
Typeclass
 
Unit iv-syntax-directed-translation
Unit iv-syntax-directed-translationUnit iv-syntax-directed-translation
Unit iv-syntax-directed-translation
 

Ähnlich wie Linked list

Linked list.pptx
Linked list.pptxLinked list.pptx
Linked list.pptxajajkhan16
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked listsAbdullah Al-hazmy
 
Unit 1 linked list
Unit 1 linked listUnit 1 linked list
Unit 1 linked listLavanyaJ28
 
linked list using c
linked list using clinked list using c
linked list using cVenkat Reddy
 
Reverse a Linked List In Place in Python
Reverse a Linked List In Place in PythonReverse a Linked List In Place in Python
Reverse a Linked List In Place in PythonKal Bartal
 
Double link list
Double link listDouble link list
Double link listAmber Wajid
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked listFahd Allebdi
 
Introduction to Linked Lists
Introduction to Linked ListsIntroduction to Linked Lists
Introduction to Linked ListsNahin Kumar Dey
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm KristinaBorooah
 
data structures and applications power p
data structures and applications power pdata structures and applications power p
data structures and applications power pMeghaKulkarni27
 
Double Linked List (Algorithm)
Double Linked List (Algorithm)Double Linked List (Algorithm)
Double Linked List (Algorithm)Huba Akhtar
 
4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1SSE_AndyLi
 

Ähnlich wie Linked list (20)

linked list
linked list linked list
linked list
 
Linked list.pptx
Linked list.pptxLinked list.pptx
Linked list.pptx
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
Unit 1 linked list
Unit 1 linked listUnit 1 linked list
Unit 1 linked list
 
linked list using c
linked list using clinked list using c
linked list using c
 
Reverse a Linked List In Place in Python
Reverse a Linked List In Place in PythonReverse a Linked List In Place in Python
Reverse a Linked List In Place in Python
 
Double link list
Double link listDouble link list
Double link list
 
Linked Lists.pdf
Linked Lists.pdfLinked Lists.pdf
Linked Lists.pdf
 
csc211_lecture_21.pptx
csc211_lecture_21.pptxcsc211_lecture_21.pptx
csc211_lecture_21.pptx
 
Linked List
Linked ListLinked List
Linked List
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Introduction to Linked Lists
Introduction to Linked ListsIntroduction to Linked Lists
Introduction to Linked Lists
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
 
data structures and applications power p
data structures and applications power pdata structures and applications power p
data structures and applications power p
 
Linked list (1).pptx
Linked list (1).pptxLinked list (1).pptx
Linked list (1).pptx
 
Double Linked List (Algorithm)
Double Linked List (Algorithm)Double Linked List (Algorithm)
Double Linked List (Algorithm)
 
4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1
 
Sy ds -I
Sy ds -ISy ds -I
Sy ds -I
 
Sy ds -I
Sy ds -ISy ds -I
Sy ds -I
 

Mehr von baabtra.com - No. 1 supplier of quality freshers

Mehr von baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Kürzlich hochgeladen

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Kürzlich hochgeladen (20)

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

Linked list

  • 1.
  • 2. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 3. Linked List Abhishek H Menon abhishekmenon@gmail.com www.facebook.com/abhishe kmenon5 twitter.com/abhishekmenon 121989 in.linkedin.com/in/Abhishek H Menon 9496519895
  • 4. Linked List • Consists of – Sequence of nodes. Each node contains a value and a link to some other node.(pointer or reference) The last node will be having a link which points to null. The list may or may not have a header.
  • 5. Linked Lists a b c d Structure of a Linked List List(Header)
  • 6. Linked List • Successor :successor of a node is the node pointing next to that node.(suc(a)=b). • Predecessor: predecessor of a node is the node pointing this node.(pre(b)=a). • The length of the linked list is the number of nodes in it.
  • 7. Linked Lists • In programming languages like C,CPP we are using “pointers ” to implement linked lists. • But in java programming, we use references instead of pointers. • To some extent both are same , but the difference is that C and CPP allows to modify pointers in anyways, and can point to anything.
  • 8. Creating references • Person p=new Person(“John”); the keyword ‘new’ creates the object and returns a references. here new Person(“John”) creates the object and returns a references to it. We can assign this reference to P.
  • 9. Creating links A B C D Class node { node next; char value; Node(char value, node n) //constructor { value=value; next=n; } }
  • 10. Creating Links • Node temp=new node(D, null); • temp=new node(C,temp); • temp=new node(B,temp); • temp=new node(A,temp); • Temp=new node(null,temp);
  • 11. Single linked list • Each node will have a value and a link to the next value(successor). • There will be a header which points either to the first element of the list, or if the list is empty it will point to the null link.
  • 13. Traversing a SLL • The following method traverses a list and print its elements. public void printFirstToLast(Node here) { while (here != null) { System.out.print(here.value + " "); here = here.next; } } You would write this as an instance method of the Node class.
  • 14. Singly Linked Lists(SLL) A B C D header here
  • 15. Inserting an element into a list • There are many ways to insert an element into a singly linked list. – As the new first element – As the new last element – Before a given node – After a given node – Before a given value – After a given value
  • 16. Inserting as a new first element • The easiest method to implement • In class Node Node insertAtFront(Node oldFront, Object value) { Node newNode = new Node(value, oldFront); return newNode; } Use this as: myList = insertAtFront(myList, value);
  • 17. Insert node after a given value void insertAfter(Object target, Object value) { for (Node here = this; here != null; here = here.next) { if (here.value.equals(target)) { Node node = new Node(value, here.next); here.next = node; return; } } // Couldn't insert--do something reasonable here! }
  • 18. Deleting a node from a SLL • In order to delete a node from a SLL, you have to change the link in its predecessor • This is slightly tricky, because you can’t follow a pointer backwards • Deleting the first node in a list is a special case, because the node’s predecessor is the list header
  • 19. Deleting a node from a SLL A B C header To delete the first element, change the link in the header.
  • 20. Deleting an element from a SLL • To delete some other element, change the link in its predecessor. A B C predecessor
  • 21. Doubly linked lists Doubly Linked List Each node contain a pointer to the successor and a pointer to its predecessor. Header points to the first element in the list and last element A B C
  • 22. Advantages and disadvantages of DLL over SLL • Advantages – Can be traversed in either direction. – Such operations such as insertion deletion becomes much easier when compared to SLL. • Disadvantages  Requires more space.  List manipulations are slower because more links are changed  Greater chance of having bugs.
  • 23. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 24. Contact Us Emerald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Ernakulam, Kerala, India. Email: info@baabtra.com