SlideShare une entreprise Scribd logo
1  sur  21
Doubly-Linked List
Doubly Linked List 
 In doubly linked list each node contains two points. 
 which points has a reference to both the next point 
and pervious point of node in list. 
 A doubly linked list is a two-way list because one 
can move in either from left to right or from right to 
left
prev next 
Info 
NODE 
Node Data 
 Info : the user’s data. 
 Prev, Next : the address of next and 
previous node in list
Operations on a Doubly linked list 
o Create list. 
o Insert element at beginning in list. 
o Insert element at end in list. 
o Insert element at any place in list. 
o Delete element from the beginning of list. 
o Delete element from the end of list. 
o Delete element from any place from list.
Create doubly linked list 
NULL 
7 X 
X 9 X
Algorithm 
Step 1: [initially list is empty] 
First = NULL 
last = NULL 
Step 2: [allocate space to newly created node] 
new1= create new node 
Step 3: [assign value to information part of node] 
info[new1]= Value 
Step 4: [assign NULL to the address part for the next] 
next[new1]= NULL 
Step 5: [check for list is empty] 
if first =NULL then 
first = new1 
last = new1 
prev[new1]= NULL 
else 
next[last]= new1 
prev[new1]=last 
last=new1 
end if 
Step 6: exit
Insert an element at beginning 
doubly linked list 
We assume linked list 
first last 
7 9 X 
X 2 X
Algorithm 
Step 1: [allocate space to newly created node] 
new1= create new node 
Step 2: [check for free space] 
if new1=NULL then 
Write “Memory full” 
Step 3: [check for list is empty] 
if first=NULL then 
Write “list is empty” 
return 
Step 4: [assign value to information part of node] 
info[new1]= Value 
Step 5: [store the node at first] 
next[new1]= first 
prev[new1]= NULL 
prev[first]= new1 
first=new1 
Step 6: exit
Insert an element at last of 
doubly linked list 
We assume linked list 
first last 
X 2 7 9 
X 4 X
Algorithm 
Step 1: [check for list is empty] 
if first=NULL then 
Write “list is empty” 
return 
Step 2: [allocate space to newly created node] 
new1= create new node 
Step 3: [assign value to information part to node] 
info[new1]= Value 
Step 4: [store the node at last] 
next[new1]= NULL 
next[last]= new1 
prev[new1]= last 
last=new1 
Step 5: exit
Insert an element at Any place 
doubly linked list 
first last 
X 2 7 9 
4 X 
We assume linked list and 
Insert after 7 valued node 
6 
tra 
t1
Algorithm 
Step 1: [check for list is empty] 
if first=NULL then 
Write “list is empty” 
return 
Step 2: [allocate space to newly created node] 
new1= create new node 
Step 3: [read values of information part of new node] 
info[new1]=value 
Step 4: [initialization] 
tra=first 
Step 5: [perform insertion operation] 
repeat through step 7 while tra != NULL
Step 6: if info[tra] =no then 
if tra=last then 
next[tra]=new1 
next[new1]=NULL 
prev[new1]=tra 
last=new1 
else 
t1=next[tra] 
next[tra]=new1 
next[new1]=t1 
prev[t1]=new1 
prev[new1]=tra 
Step 7: [increment temp value] 
tra=next[tra] 
Step 8: exit
Delete an element at beginning 
of doubly linked list 
first last 
X 2 7 9 
4 X 
We assume linked list 
ffirst 
X
Algorithm 
Step 1: [check for list is empty] 
if first=NULL then 
Write “list is empty” 
return 
Step 2: [perform deletion opration] 
if first=last then 
first=NULL 
last=NULL 
free(first) 
else 
ffirst=next[first] 
free(first) 
first=ffirst 
prev[first]=NULL 
end if 
Step 3: exit
Delete an element at last of 
doubly linked list 
first last 
X 2 7 9 
4 X 
We assume linked list 
t 
X
Algorithm 
Step 1: [check for list is empty] 
if first=NULL then 
Write “list is empty” 
return 
Step 2: [perform deletion opration] 
if first=last then 
first=NULL 
last=NULL 
free(first) 
else 
t=prev[last] 
free(last) 
last=t 
next[last]=NULL 
Step 3: exit
Delete an element at any place 
doubly linked list 
We assume linked list and 
Delete 7 valued node 
first last 
X 2 7 9 
4 X 
tra 
t1 
pr1
Algorithm eny delete 
Step 1: [check for list is empty] 
if first=NULL then 
Write “list is empty” 
return 
Step 2: [perform deletion opration] 
if first=last then 
first=NULL 
last=NULL 
free(first) 
Step 3: [initialization] 
tra=first 
Step 4: [perform insertion operation] 
repeat through step 7 while tra != NULL
Step 5: IF info[tra]=number then 
if tra=first then 
ffirst=next[first] 
free(first) 
first=ffirst 
else if tra=first then 
free(last) 
last=pr1 
next[last]=NULL 
else 
t1=next[tra] 
next[pr1]=t1 
prev[t1]=pr1 
free(tra) 
last=t1 
Step 6: [Assign previous value of tra to prev] 
pr1=tra 
Step 7: [increment temp value] 
tra=next[tra] 
Step 8: exit
Doubly Linked List Structure and Common Operations

Contenu connexe

Tendances

Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked ListReazul Islam
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListManishPrajapati78
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structuresDurgaDeviCbit
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsShubham Sharma
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked listsAbdullah Al-hazmy
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structureschauhankapil
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applicationssomendra kumar
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Balwant Gorad
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure Janki Shah
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureZidny Nafan
 

Tendances (20)

Singly link list
Singly link listSingly link list
Singly link list
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
 
Linked list
Linked listLinked list
Linked list
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || Algorithms
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
Binary search tree in data structures
Binary search tree in  data structuresBinary search tree in  data structures
Binary search tree in data structures
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Linked lists
Linked listsLinked lists
Linked lists
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
 
Linked list
Linked listLinked list
Linked list
 
Stack
StackStack
Stack
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
stack presentation
stack presentationstack presentation
stack presentation
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 

Similaire à Doubly Linked List Structure and Common Operations

Similaire à Doubly Linked List Structure and Common Operations (20)

Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queues
 
Ppt of operations on one way link list
Ppt of operations on one way  link listPpt of operations on one way  link list
Ppt of operations on one way link list
 
Ppt of operations on one way link list
Ppt of operations on one way  link listPpt of operations on one way  link list
Ppt of operations on one way link list
 
Sorting
SortingSorting
Sorting
 
Linked list
Linked listLinked list
Linked list
 
Unit III Version I.pptx
Unit III Version I.pptxUnit III Version I.pptx
Unit III Version I.pptx
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
 
Linked list
Linked listLinked list
Linked list
 
linkrd_list.pdf
linkrd_list.pdflinkrd_list.pdf
linkrd_list.pdf
 
Stack q ll algo
Stack q ll algoStack q ll algo
Stack q ll algo
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 

Dernier

SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 

Dernier (20)

Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 

Doubly Linked List Structure and Common Operations

  • 2. Doubly Linked List  In doubly linked list each node contains two points.  which points has a reference to both the next point and pervious point of node in list.  A doubly linked list is a two-way list because one can move in either from left to right or from right to left
  • 3. prev next Info NODE Node Data  Info : the user’s data.  Prev, Next : the address of next and previous node in list
  • 4. Operations on a Doubly linked list o Create list. o Insert element at beginning in list. o Insert element at end in list. o Insert element at any place in list. o Delete element from the beginning of list. o Delete element from the end of list. o Delete element from any place from list.
  • 5. Create doubly linked list NULL 7 X X 9 X
  • 6. Algorithm Step 1: [initially list is empty] First = NULL last = NULL Step 2: [allocate space to newly created node] new1= create new node Step 3: [assign value to information part of node] info[new1]= Value Step 4: [assign NULL to the address part for the next] next[new1]= NULL Step 5: [check for list is empty] if first =NULL then first = new1 last = new1 prev[new1]= NULL else next[last]= new1 prev[new1]=last last=new1 end if Step 6: exit
  • 7. Insert an element at beginning doubly linked list We assume linked list first last 7 9 X X 2 X
  • 8. Algorithm Step 1: [allocate space to newly created node] new1= create new node Step 2: [check for free space] if new1=NULL then Write “Memory full” Step 3: [check for list is empty] if first=NULL then Write “list is empty” return Step 4: [assign value to information part of node] info[new1]= Value Step 5: [store the node at first] next[new1]= first prev[new1]= NULL prev[first]= new1 first=new1 Step 6: exit
  • 9. Insert an element at last of doubly linked list We assume linked list first last X 2 7 9 X 4 X
  • 10. Algorithm Step 1: [check for list is empty] if first=NULL then Write “list is empty” return Step 2: [allocate space to newly created node] new1= create new node Step 3: [assign value to information part to node] info[new1]= Value Step 4: [store the node at last] next[new1]= NULL next[last]= new1 prev[new1]= last last=new1 Step 5: exit
  • 11. Insert an element at Any place doubly linked list first last X 2 7 9 4 X We assume linked list and Insert after 7 valued node 6 tra t1
  • 12. Algorithm Step 1: [check for list is empty] if first=NULL then Write “list is empty” return Step 2: [allocate space to newly created node] new1= create new node Step 3: [read values of information part of new node] info[new1]=value Step 4: [initialization] tra=first Step 5: [perform insertion operation] repeat through step 7 while tra != NULL
  • 13. Step 6: if info[tra] =no then if tra=last then next[tra]=new1 next[new1]=NULL prev[new1]=tra last=new1 else t1=next[tra] next[tra]=new1 next[new1]=t1 prev[t1]=new1 prev[new1]=tra Step 7: [increment temp value] tra=next[tra] Step 8: exit
  • 14. Delete an element at beginning of doubly linked list first last X 2 7 9 4 X We assume linked list ffirst X
  • 15. Algorithm Step 1: [check for list is empty] if first=NULL then Write “list is empty” return Step 2: [perform deletion opration] if first=last then first=NULL last=NULL free(first) else ffirst=next[first] free(first) first=ffirst prev[first]=NULL end if Step 3: exit
  • 16. Delete an element at last of doubly linked list first last X 2 7 9 4 X We assume linked list t X
  • 17. Algorithm Step 1: [check for list is empty] if first=NULL then Write “list is empty” return Step 2: [perform deletion opration] if first=last then first=NULL last=NULL free(first) else t=prev[last] free(last) last=t next[last]=NULL Step 3: exit
  • 18. Delete an element at any place doubly linked list We assume linked list and Delete 7 valued node first last X 2 7 9 4 X tra t1 pr1
  • 19. Algorithm eny delete Step 1: [check for list is empty] if first=NULL then Write “list is empty” return Step 2: [perform deletion opration] if first=last then first=NULL last=NULL free(first) Step 3: [initialization] tra=first Step 4: [perform insertion operation] repeat through step 7 while tra != NULL
  • 20. Step 5: IF info[tra]=number then if tra=first then ffirst=next[first] free(first) first=ffirst else if tra=first then free(last) last=pr1 next[last]=NULL else t1=next[tra] next[pr1]=t1 prev[t1]=pr1 free(tra) last=t1 Step 6: [Assign previous value of tra to prev] pr1=tra Step 7: [increment temp value] tra=next[tra] Step 8: exit