SlideShare ist ein Scribd-Unternehmen logo
1 von 22
data next
A singly linked list is a concrete data
structure consisting of a sequence of
nodes.
Each node stores:-
element
link to the next node
struct Node
{ int item
Node *next;
};
Inserting at the Head
1. Allocate a new
node
2. Insert new
element
3. Make new node
point to old
head
4. Update head to
point to new
node
void insertLL(Struct Node
*newNode)
{
if (newNode == NULL)
return;
else {
if (head == NULL) {
newNode->next = NULL;
head = newNode;
tail = newNode;
}
else {
newNode->next = head;
head = newNode;
}
}
}
Inserting at the Head
Update the next link of a new node, to
point to the current head node.
Update head link to point to the new
node.
Removing at the Head
void removeFirst()
{
if (head == NULL)
return;
else {
Struct Node *removedNode;
removedNode = head;
if (head == tail) {
head = NULL;
tail = NULL;
} else {
head = head->next;
}
delete removedNode;
}
}
1. Update head to
point to next node
in the list
2. Allow garbage
collector to reclaim
the former first
node
Update head link to point to the node,
next to the head.
Dispose removed node.
void insert(Struct Node*newNode)
{
if (newNode == NULL)
return;
else {
newNode->next = NULL;
if (head == NULL) {
head = newNode;
tail = newNode;
} else {
tail->next = newNode;
tail = newNode;
}
}
}
1. Allocate a new
node
2. Insert new element
3. Have new node
point to null
4. Have old last node
point to new node
5. Update tail to point
to new node
Inserting at the Tail
Update the next link of the current tail
node, to point to the new node.
Update tail link to point to the new
node
Insertion between two nodes
New node is always inserted between two nodes, which
are already in the list. Head and tail links are not updated
in this case.
Update link of the "previous" node,
to point to the new node.
Update link of the new node, to
point to the "next" node.
 It is a way of going both directions in a
linked list, forward and reverse.
 Many applications require a quick access
to the predecessor node of some node in
list.
Doubly-Linked Lists
prevnext
Algorithm addFirst(v):
w = header.getNext() // the
current first node
v.setNext(w)
w.setPrev(v)
header.setNext(v)
v.setPrev(header)
size++
Algorithm removeLast():
v = trailer.getPrev() // the
current last node
if (v = = header) then
Indicate an error: the list
is empty
prev = v.getPrev()
prev.setNext(trailer)
trailer.setPrev(prev)
v.setPrev(null)
v.setNext(null)
size--
‱If programming in C, there are no “grow able-arrays”, so
typically linked lists used when# elements in a collection
varies, isn’t known, can’t be fixed at compile time
Could grow array, potentially expensive/wasteful especially if #
elements is small.
Also need# elements in array, requires extra parameter
With linked list, one pointer used to access all the elements in a
collection
‱Simulation/modelling of DNA gene-splicing
Given list of millions of CGTA... for DNA strand, find locations where
new DNA/gene can be spliced
‱Remove element from middle of a collection,
maintain order, no shifting. Add an element in the
middle, no shifting
What’s the problem with a vector (array)?
Emacs visits several files, internally keeps a linked-list of
buffers
Naively keep characters in a linked list, but in practice too much storage,
 need more esoteric data structures
‱What’s (3x5+ 2x3+ x + 5) + (2x4+ 5x3+ x2+4x) ?
As a vector (3, 0, 2, 0, 1, 5)and (0, 2, 5, 1, 4, 0)
As a list ((3,5), (2,3), (1,1), (5,0))and ________?
Most polynomial operations sequentially visit terms, don’t need random
access, do need “splicing”

Weitere Àhnliche Inhalte

Was ist angesagt?

Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stackvaibhav2910
 
Singly linked list
Singly linked listSingly linked list
Singly linked listAmar Jukuntla
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
Linked list
Linked listLinked list
Linked listeShikshak
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonchanna basava
 
358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5sumitbardhan
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked ListsAfaq Mansoor Khan
 
Selection sort and insertion sort
Selection sort and insertion sortSelection sort and insertion sort
Selection sort and insertion sortMay Ann Mendoza
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure Janki Shah
 
Linked list
Linked listLinked list
Linked listVONI
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked ListNinad Mankar
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsShubham Sharma
 
Red black tree
Red black treeRed black tree
Red black treeRajendran
 
skip list
skip listskip list
skip listiammutex
 
Singly link list
Singly link listSingly link list
Singly link listRojin Khadka
 

Was ist angesagt? (20)

Linked lists
Linked listsLinked lists
Linked lists
 
Linked lists
Linked listsLinked lists
Linked lists
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Linked list
Linked listLinked list
Linked list
 
List , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in pythonList , tuples, dictionaries and regular expressions in python
List , tuples, dictionaries and regular expressions in python
 
Trees
TreesTrees
Trees
 
358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
 
Selection sort and insertion sort
Selection sort and insertion sortSelection sort and insertion sort
Selection sort and insertion sort
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Linked list
Linked listLinked list
Linked list
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || Algorithms
 
Red black tree
Red black treeRed black tree
Red black tree
 
skip list
skip listskip list
skip list
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Singly link list
Singly link listSingly link list
Singly link list
 

Andere mochten auch

Car Parking System (Singly linked list )
Car Parking System (Singly linked list ) Car Parking System (Singly linked list )
Car Parking System (Singly linked list ) S. M. Shakib Limon
 
Singly linked lists
Singly linked listsSingly linked lists
Singly linked listsJonghoon Park
 
Data Structure Lecture 6
Data Structure Lecture 6Data Structure Lecture 6
Data Structure Lecture 6Teksify
 
Linked list without animation
Linked list without animationLinked list without animation
Linked list without animationLovelyn Rose
 

Andere mochten auch (6)

Car Parking System (Singly linked list )
Car Parking System (Singly linked list ) Car Parking System (Singly linked list )
Car Parking System (Singly linked list )
 
Singly linked lists
Singly linked listsSingly linked lists
Singly linked lists
 
Data Structure Lecture 6
Data Structure Lecture 6Data Structure Lecture 6
Data Structure Lecture 6
 
Linked list without animation
Linked list without animationLinked list without animation
Linked list without animation
 
Team 10
Team 10Team 10
Team 10
 
linked list
linked list linked list
linked list
 

Ähnlich wie LINKED LISTS

in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfin Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfsauravmanwanicp
 
Data Structure Suppose a singly linked list is implemented with refere.docx
Data Structure Suppose a singly linked list is implemented with refere.docxData Structure Suppose a singly linked list is implemented with refere.docx
Data Structure Suppose a singly linked list is implemented with refere.docxcliftonl1
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03Nasir Mehmood
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfarjunenterprises1978
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]Muhammad Hammad Waseem
 
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 The MyLinkedList class used in Listing 24.6 is a one-way directional .docx The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
The MyLinkedList class used in Listing 24.6 is a one-way directional .docxKomlin1
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.pptssuser0be977
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
 
CSE240 Doubly Linked Lists
CSE240 Doubly Linked ListsCSE240 Doubly Linked Lists
CSE240 Doubly Linked ListsGarrett Gutierrez
 
I need to implment a function that can reverse a single linked list..pdf
I need to implment a function that can reverse a single linked list..pdfI need to implment a function that can reverse a single linked list..pdf
I need to implment a function that can reverse a single linked list..pdfrohit219406
 
linkedlistwith animations.ppt
linkedlistwith animations.pptlinkedlistwith animations.ppt
linkedlistwith animations.pptMuhammadShafi89
 
Obyerrives- - More prectice on linked lists - Create a suctod list wit.pdf
Obyerrives- - More prectice on linked lists - Create a suctod list wit.pdfObyerrives- - More prectice on linked lists - Create a suctod list wit.pdf
Obyerrives- - More prectice on linked lists - Create a suctod list wit.pdfacrylicBangles
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfrozakashif85
 

Ähnlich wie LINKED LISTS (20)

Linkedlist
LinkedlistLinkedlist
Linkedlist
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfin Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
 
Data Structure Suppose a singly linked list is implemented with refere.docx
Data Structure Suppose a singly linked list is implemented with refere.docxData Structure Suppose a singly linked list is implemented with refere.docx
Data Structure Suppose a singly linked list is implemented with refere.docx
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdf
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Linked list
Linked listLinked list
Linked list
 
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 The MyLinkedList class used in Listing 24.6 is a one-way directional .docx The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
CSE240 Doubly Linked Lists
CSE240 Doubly Linked ListsCSE240 Doubly Linked Lists
CSE240 Doubly Linked Lists
 
I need to implment a function that can reverse a single linked list..pdf
I need to implment a function that can reverse a single linked list..pdfI need to implment a function that can reverse a single linked list..pdf
I need to implment a function that can reverse a single linked list..pdf
 
linkedlistwith animations.ppt
linkedlistwith animations.pptlinkedlistwith animations.ppt
linkedlistwith animations.ppt
 
Obyerrives- - More prectice on linked lists - Create a suctod list wit.pdf
Obyerrives- - More prectice on linked lists - Create a suctod list wit.pdfObyerrives- - More prectice on linked lists - Create a suctod list wit.pdf
Obyerrives- - More prectice on linked lists - Create a suctod list wit.pdf
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
Doc 20180130-wa0003
Doc 20180130-wa0003Doc 20180130-wa0003
Doc 20180130-wa0003
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
 
DS Unit 2.ppt
DS Unit 2.pptDS Unit 2.ppt
DS Unit 2.ppt
 

KĂŒrzlich hochgeladen

Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptNarmatha D
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsDILIPKUMARMONDAL6
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadaditya806802
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfRajuKanojiya4
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...Amil Baba Dawood bangali
 
Gurgaon âœĄïž9711147426✹Call In girls Gurgaon Sector 51 escort service
Gurgaon âœĄïž9711147426✹Call In girls Gurgaon Sector 51 escort serviceGurgaon âœĄïž9711147426✹Call In girls Gurgaon Sector 51 escort service
Gurgaon âœĄïž9711147426✹Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxVelmuruganTECE
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating SystemRashmi Bhat
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsSachinPawar510423
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 

KĂŒrzlich hochgeladen (20)

Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.ppt
 
The SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teamsThe SRE Report 2024 - Great Findings for the teams
The SRE Report 2024 - Great Findings for the teams
 
home automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasadhome automation using Arduino by Aditya Prasad
home automation using Arduino by Aditya Prasad
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdf
 
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
NO1 Certified Black Magic Specialist Expert Amil baba in Uae Dubai Abu Dhabi ...
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Gurgaon âœĄïž9711147426✹Call In girls Gurgaon Sector 51 escort service
Gurgaon âœĄïž9711147426✹Call In girls Gurgaon Sector 51 escort serviceGurgaon âœĄïž9711147426✹Call In girls Gurgaon Sector 51 escort service
Gurgaon âœĄïž9711147426✹Call In girls Gurgaon Sector 51 escort service
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptx
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documents
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 

LINKED LISTS

  • 1.
  • 2.
  • 3. data next A singly linked list is a concrete data structure consisting of a sequence of nodes. Each node stores:- element link to the next node struct Node { int item Node *next; };
  • 4. Inserting at the Head 1. Allocate a new node 2. Insert new element 3. Make new node point to old head 4. Update head to point to new node void insertLL(Struct Node *newNode) { if (newNode == NULL) return; else { if (head == NULL) { newNode->next = NULL; head = newNode; tail = newNode; } else { newNode->next = head; head = newNode; } } }
  • 6. Update the next link of a new node, to point to the current head node.
  • 7. Update head link to point to the new node.
  • 8. Removing at the Head void removeFirst() { if (head == NULL) return; else { Struct Node *removedNode; removedNode = head; if (head == tail) { head = NULL; tail = NULL; } else { head = head->next; } delete removedNode; } } 1. Update head to point to next node in the list 2. Allow garbage collector to reclaim the former first node
  • 9. Update head link to point to the node, next to the head.
  • 11.
  • 12. void insert(Struct Node*newNode) { if (newNode == NULL) return; else { newNode->next = NULL; if (head == NULL) { head = newNode; tail = newNode; } else { tail->next = newNode; tail = newNode; } } } 1. Allocate a new node 2. Insert new element 3. Have new node point to null 4. Have old last node point to new node 5. Update tail to point to new node Inserting at the Tail
  • 13. Update the next link of the current tail node, to point to the new node.
  • 14. Update tail link to point to the new node
  • 15. Insertion between two nodes New node is always inserted between two nodes, which are already in the list. Head and tail links are not updated in this case.
  • 16. Update link of the "previous" node, to point to the new node.
  • 17. Update link of the new node, to point to the "next" node.
  • 18.  It is a way of going both directions in a linked list, forward and reverse.  Many applications require a quick access to the predecessor node of some node in list. Doubly-Linked Lists prevnext
  • 19. Algorithm addFirst(v): w = header.getNext() // the current first node v.setNext(w) w.setPrev(v) header.setNext(v) v.setPrev(header) size++
  • 20. Algorithm removeLast(): v = trailer.getPrev() // the current last node if (v = = header) then Indicate an error: the list is empty prev = v.getPrev() prev.setNext(trailer) trailer.setPrev(prev) v.setPrev(null) v.setNext(null) size--
  • 21. ‱If programming in C, there are no “grow able-arrays”, so typically linked lists used when# elements in a collection varies, isn’t known, can’t be fixed at compile time Could grow array, potentially expensive/wasteful especially if # elements is small. Also need# elements in array, requires extra parameter With linked list, one pointer used to access all the elements in a collection ‱Simulation/modelling of DNA gene-splicing Given list of millions of CGTA... for DNA strand, find locations where new DNA/gene can be spliced
  • 22. ‱Remove element from middle of a collection, maintain order, no shifting. Add an element in the middle, no shifting What’s the problem with a vector (array)? Emacs visits several files, internally keeps a linked-list of buffers Naively keep characters in a linked list, but in practice too much storage,  need more esoteric data structures ‱What’s (3x5+ 2x3+ x + 5) + (2x4+ 5x3+ x2+4x) ? As a vector (3, 0, 2, 0, 1, 5)and (0, 2, 5, 1, 4, 0) As a list ((3,5), (2,3), (1,1), (5,0))and ________? Most polynomial operations sequentially visit terms, don’t need random access, do need “splicing”