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

More Related Content

What's hot

Linked lists
Linked listsLinked lists
Linked lists
SARITHA REDDY
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
chauhankapil
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
Syed Zaid Irshad
 
Singly link list
Singly link listSingly link list
Singly link list
Rojin Khadka
 
Single linked list
Single linked listSingle linked list
Single linked list
jasbirsingh chauhan
 
Linked list
Linked listLinked list
Linked list
Md. Afif Al Mamun
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
chauhankapil
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
DivyeshKumar Jagatiya
 
Linked list
Linked list Linked list
Linked list
Arbind Mandal
 
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
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Lovely Professional University
 
Trees
TreesTrees
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stackvaibhav2910
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
Krish_ver2
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Albin562191
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
Mandeep Singh
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
Rojan Pariyar
 
Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
Dr. Sindhia Lingaswamy
 

What's hot (20)

Linked lists
Linked listsLinked lists
Linked lists
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Singly link list
Singly link listSingly link list
Singly link list
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Linked list
Linked listLinked list
Linked list
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
Linked list
Linked list Linked list
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]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Trees
TreesTrees
Trees
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptx
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
 
Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
 

Viewers also liked

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
 
Data Structure Lecture 6
Data Structure Lecture 6Data Structure Lecture 6
Data Structure Lecture 6
Teksify
 
Linked list without animation
Linked list without animationLinked list without animation
Linked list without animation
Lovelyn Rose
 
linked list
linked list linked list
linked list
Mohaimin Rahat
 

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

Similar to LINKED LISTS

Linkedlist
LinkedlistLinkedlist
Linkedlist
Masud Parvaze
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
Himadri Sen Gupta
 
Singly Linked List_Operations-Traversal.pptx
Singly Linked List_Operations-Traversal.pptxSingly Linked List_Operations-Traversal.pptx
Singly Linked List_Operations-Traversal.pptx
ssusera965f6
 
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
sauravmanwanicp
 
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
cliftonl1
 
Data Structures and Agorithm: DS 04 Linked List.pptx
Data Structures and Agorithm: DS 04 Linked List.pptxData Structures and Agorithm: DS 04 Linked List.pptx
Data Structures and Agorithm: DS 04 Linked List.pptx
RashidFaridChishti
 
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptxData Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
RashidFaridChishti
 
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..pdf
arjunenterprises1978
 
Linked list
Linked listLinked list
Linked list
Ajharul Abedeen
 
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
Komlin1
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
ssuser0be977
 
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
EricvtJFraserr
 
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
rohit219406
 
linkedlistwith animations.ppt
linkedlistwith animations.pptlinkedlistwith animations.ppt
linkedlistwith animations.ppt
MuhammadShafi89
 
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
acrylicBangles
 

Similar to LINKED LISTS (20)

Linkedlist
LinkedlistLinkedlist
Linkedlist
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
Singly Linked List_Operations-Traversal.pptx
Singly Linked List_Operations-Traversal.pptxSingly Linked List_Operations-Traversal.pptx
Singly Linked List_Operations-Traversal.pptx
 
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 and Agorithm: DS 04 Linked List.pptx
Data Structures and Agorithm: DS 04 Linked List.pptxData Structures and Agorithm: DS 04 Linked List.pptx
Data Structures and Agorithm: DS 04 Linked List.pptx
 
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptxData Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
 
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
 
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
 

Recently uploaded

MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 

Recently uploaded (20)

MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 

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”