SlideShare a Scribd company logo
Lecture # 4Lecture # 4
Doubly Link ListDoubly Link List
 In aIn a DoublyDoubly linked listlinked list, each, each itemitem is allocated spaceis allocated space
as it is added to the list. Aas it is added to the list. A linklink is kept with eachis kept with each
item to theitem to the next itemnext item andand previous itemprevious item in the list.in the list.
 Each node of the list hasEach node of the list has threethree elements:elements:
 TheThe itemitem being stored in the listbeing stored in the list
 A pointer to theA pointer to the nextnext item in the listitem in the list
 A pointer to theA pointer to the previousprevious item in the listitem in the list
 The last node in the list contains aThe last node in the list contains a NULLNULL pointerpointer
(next)(next) to indicate that it is theto indicate that it is the endend oror tailtail of the listof the list
and first node containsand first node contains NULLNULL pointer forpointer for previousprevious
pointer to indicate that it ispointer to indicate that it is headhead of the Link List.of the Link List.
 Figure showingFigure showing Doubly Link ListDoubly Link List …..…..
BA EC
headhead
D NULLNULL
NULNUL
LL
Structure corresponding to above will beStructure corresponding to above will be
struct nodestruct node
{{
char info;char info;
node *next;node *next;
node *previous;node *previous;
};};
Adding element - Doubly-Linked ListAdding element - Doubly-Linked List
Deletion - Doubly-Linked ListDeletion - Doubly-Linked List
 How ….How ….
 Think yourselfThink yourself
 Discussion from Implementation (code)Discussion from Implementation (code)
point of view.point of view.
 Ring data structure can be regarded asRing data structure can be regarded as
circular Link Listcircular Link List..
 In Link List, instead of making last node’sIn Link List, instead of making last node’s
next pointer to NULL, we can assign ornext pointer to NULL, we can assign or
point it to head node so that it sounds aspoint it to head node so that it sounds as
ring data structure as follows.ring data structure as follows.
Circular Link List (Ring)Circular Link List (Ring)
 Figure showingFigure showing RingRing…..…..
BA EC
headhead
D
OROR
B
A
E
C
headhead
D
Josephus ProblemJosephus Problem
 A case where circularly linked list is handy toA case where circularly linked list is handy to
provide the solution of theprovide the solution of the Josephus ProblemJosephus Problem..
 Consider there areConsider there are 1010 persons. They would like topersons. They would like to
choose achoose a leaderleader..
 The way they decide is thatThe way they decide is that all 10 sit in a circleall 10 sit in a circle..
 They start a count with personThey start a count with person 11 and go inand go in
clockwise direction and skipclockwise direction and skip 3.3. PersonPerson 44 reachedreached
is eliminated.is eliminated.
 The count starts with the fifth and the next personThe count starts with the fifth and the next person
to go is the fourth in count.to go is the fourth in count.
 Eventually, a single person remains.Eventually, a single person remains.
Lecture4
Lecture4
Lecture4
Lecture4
Lecture4
Lecture4
Lecture4
Lecture4
Lecture4
Lecture4
 Doubly RingDoubly Ring data structure can be regarded asdata structure can be regarded as
Circular Doubly Link ListCircular Doubly Link List..
 InIn Circular Doubly Link ListCircular Doubly Link List, instead of making last, instead of making last
node’snode’s nextnext pointer to NULL, We assign or point itpointer to NULL, We assign or point it
toto headhead node. Similarly,node. Similarly, firstfirst (head) node’s(head) node’s
previousprevious pointer is pointed to last node in list . sopointer is pointed to last node in list . so
that it sounds asthat it sounds as Doubly RingDoubly Ring data structure.data structure.
Doubly RingDoubly Ring
 Figure showingFigure showing DoublyDoubly RingRing…..…..
BA EC
headhead
D
OROR
B
A
E
C
headhead
D
Assignment # 3Assignment # 3
 Implement aImplement a Josephus ProblemJosephus Problem discusseddiscussed
above with following conditions.above with following conditions.
 Decide value ofDecide value of MM andand NN at run time.at run time.
 AssignAssign numbersnumbers to every node.to every node.
 Initiate the problem from node numberInitiate the problem from node number 11..
 Submission Due DateSubmission Due Date:: Next week, same dayNext week, same day
(In Office Hours)(In Office Hours)

More Related Content

What's hot (20)

PPT
Unit ii(dsc++)
Durga Devi
 
PPT
Circular linked list
dchuynh
 
PPTX
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
PPTX
Linked lists 1
naymulhaque
 
PPTX
Linked lists in Data Structure
Muhazzab Chouhadry
 
PPSX
Data Structure (Double Linked List)
Adam Mukharil Bachtiar
 
PPTX
Linked list
VONI
 
PPT
header, circular and two way linked lists
student
 
PPSX
Data Structure (Dynamic Array and Linked List)
Adam Mukharil Bachtiar
 
PPTX
CSE240 Doubly Linked Lists
Garrett Gutierrez
 
PPTX
Doubly linked list
Fahd Allebdi
 
PPTX
Linklist
SHEETAL WAGHMARE
 
PPSX
Data Structure (Circular Linked List)
Adam Mukharil Bachtiar
 
PDF
Circular linked list
maamir farooq
 
PPTX
Linked lists a
Khuram Shahzad
 
PPT
Linked list
eShikshak
 
PPT
Data Structure lec#2
University of Gujrat, Pakistan
 
PPTX
Chapter 17 Tuples
Praveen M Jigajinni
 
PPTX
Linked list
Dr. Shashank Shetty
 
Unit ii(dsc++)
Durga Devi
 
Circular linked list
dchuynh
 
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
Linked lists 1
naymulhaque
 
Linked lists in Data Structure
Muhazzab Chouhadry
 
Data Structure (Double Linked List)
Adam Mukharil Bachtiar
 
Linked list
VONI
 
header, circular and two way linked lists
student
 
Data Structure (Dynamic Array and Linked List)
Adam Mukharil Bachtiar
 
CSE240 Doubly Linked Lists
Garrett Gutierrez
 
Doubly linked list
Fahd Allebdi
 
Data Structure (Circular Linked List)
Adam Mukharil Bachtiar
 
Circular linked list
maamir farooq
 
Linked lists a
Khuram Shahzad
 
Linked list
eShikshak
 
Data Structure lec#2
University of Gujrat, Pakistan
 
Chapter 17 Tuples
Praveen M Jigajinni
 
Linked list
Dr. Shashank Shetty
 

Similar to Lecture4 (20)

PPTX
Doubly & Circular Linked Lists
Afaq Mansoor Khan
 
PPTX
Deleting a node from the list(SINGLE LINKED LIST)
JayasankarShyam
 
PPTX
Linear data structure concepts
Akila Krishnamoorthy
 
PPTX
linked list_MODULE 3.pptx ppt on the linked list
AnuragKumar682871
 
PPTX
Data structures
Rokonuzzaman Rony
 
PPTX
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
vaibhavkore8
 
PPTX
Lec5-Doubly-Linked-List-24102022-110112am.pptx
IqraHanif27
 
PPT
linked-list.ppt
DikkySuryadiSKomMKom
 
PPTX
Linked List in Data Structure
Meghaj Mallick
 
PPTX
linkedlist.pptx
MeghaKulkarni27
 
PPTX
linked list in data structure
shameen khan
 
PDF
computer notes - Circular list
ecomputernotes
 
DOC
Linked List
Md gulam sarwar
 
PPTX
Ll.pptx
chin463670
 
PPTX
linked list.pptx
chin463670
 
PPTX
Linked list (1).pptx
rajveersingh643731
 
PPTX
Data Structures Introduction & Linear DS
sailaja156145
 
PPTX
Linked list using Dynamic Memory Allocation
kiran Patel
 
PDF
ds-lecture-4-171012041008 (1).pdf
KamranAli649587
 
Doubly & Circular Linked Lists
Afaq Mansoor Khan
 
Deleting a node from the list(SINGLE LINKED LIST)
JayasankarShyam
 
Linear data structure concepts
Akila Krishnamoorthy
 
linked list_MODULE 3.pptx ppt on the linked list
AnuragKumar682871
 
Data structures
Rokonuzzaman Rony
 
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
vaibhavkore8
 
Lec5-Doubly-Linked-List-24102022-110112am.pptx
IqraHanif27
 
linked-list.ppt
DikkySuryadiSKomMKom
 
Linked List in Data Structure
Meghaj Mallick
 
linkedlist.pptx
MeghaKulkarni27
 
linked list in data structure
shameen khan
 
computer notes - Circular list
ecomputernotes
 
Linked List
Md gulam sarwar
 
Ll.pptx
chin463670
 
linked list.pptx
chin463670
 
Linked list (1).pptx
rajveersingh643731
 
Data Structures Introduction & Linear DS
sailaja156145
 
Linked list using Dynamic Memory Allocation
kiran Patel
 
ds-lecture-4-171012041008 (1).pdf
KamranAli649587
 
Ad

More from Muhammad Zubair (12)

PPTX
Cloud computing
Muhammad Zubair
 
PPTX
Cloud computing disadvantages
Muhammad Zubair
 
PPT
Lecture10
Muhammad Zubair
 
PPT
Lecture9 recursion
Muhammad Zubair
 
PPT
Lecture8
Muhammad Zubair
 
PPT
Lecture7
Muhammad Zubair
 
PPT
Lecture6
Muhammad Zubair
 
PPT
Lecture5
Muhammad Zubair
 
PPT
Lecture3
Muhammad Zubair
 
PPT
Lecture1
Muhammad Zubair
 
DOCX
Indin report by zubair
Muhammad Zubair
 
DOCX
Cyber crime in pakistan by zubair
Muhammad Zubair
 
Cloud computing
Muhammad Zubair
 
Cloud computing disadvantages
Muhammad Zubair
 
Lecture10
Muhammad Zubair
 
Lecture9 recursion
Muhammad Zubair
 
Lecture8
Muhammad Zubair
 
Lecture7
Muhammad Zubair
 
Lecture6
Muhammad Zubair
 
Lecture5
Muhammad Zubair
 
Lecture3
Muhammad Zubair
 
Lecture1
Muhammad Zubair
 
Indin report by zubair
Muhammad Zubair
 
Cyber crime in pakistan by zubair
Muhammad Zubair
 
Ad

Recently uploaded (20)

PPTX
MALABSORPTION SYNDROME: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
PPTX
HERNIA: INGUINAL HERNIA, UMBLICAL HERNIA.pptx
PRADEEP ABOTHU
 
PPTX
Nutrition Quiz bee for elementary 2025 1.pptx
RichellMarianoPugal
 
PPTX
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
PPTX
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PDF
Module 1: Determinants of Health [Tutorial Slides]
JonathanHallett4
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PPTX
Constitutional Design Civics Class 9.pptx
bikesh692
 
PPTX
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
PPTX
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
PDF
Exploring-the-Investigative-World-of-Science.pdf/8th class curiosity/1st chap...
Sandeep Swamy
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PPTX
INTESTINAL OBSTRUCTION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPT
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
PPTX
GENERAL METHODS OF ISOLATION AND PURIFICATION OF MARINE__MPHARM.pptx
SHAHEEN SHABBIR
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
MALABSORPTION SYNDROME: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
HERNIA: INGUINAL HERNIA, UMBLICAL HERNIA.pptx
PRADEEP ABOTHU
 
Nutrition Quiz bee for elementary 2025 1.pptx
RichellMarianoPugal
 
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
Virus sequence retrieval from NCBI database
yamunaK13
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
Module 1: Determinants of Health [Tutorial Slides]
JonathanHallett4
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
Constitutional Design Civics Class 9.pptx
bikesh692
 
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
Exploring-the-Investigative-World-of-Science.pdf/8th class curiosity/1st chap...
Sandeep Swamy
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
INTESTINAL OBSTRUCTION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
GENERAL METHODS OF ISOLATION AND PURIFICATION OF MARINE__MPHARM.pptx
SHAHEEN SHABBIR
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 

Lecture4

  • 3.  In aIn a DoublyDoubly linked listlinked list, each, each itemitem is allocated spaceis allocated space as it is added to the list. Aas it is added to the list. A linklink is kept with eachis kept with each item to theitem to the next itemnext item andand previous itemprevious item in the list.in the list.  Each node of the list hasEach node of the list has threethree elements:elements:  TheThe itemitem being stored in the listbeing stored in the list  A pointer to theA pointer to the nextnext item in the listitem in the list  A pointer to theA pointer to the previousprevious item in the listitem in the list  The last node in the list contains aThe last node in the list contains a NULLNULL pointerpointer (next)(next) to indicate that it is theto indicate that it is the endend oror tailtail of the listof the list and first node containsand first node contains NULLNULL pointer forpointer for previousprevious pointer to indicate that it ispointer to indicate that it is headhead of the Link List.of the Link List.
  • 4.  Figure showingFigure showing Doubly Link ListDoubly Link List …..….. BA EC headhead D NULLNULL NULNUL LL Structure corresponding to above will beStructure corresponding to above will be struct nodestruct node {{ char info;char info; node *next;node *next; node *previous;node *previous; };};
  • 5. Adding element - Doubly-Linked ListAdding element - Doubly-Linked List
  • 6. Deletion - Doubly-Linked ListDeletion - Doubly-Linked List  How ….How ….  Think yourselfThink yourself  Discussion from Implementation (code)Discussion from Implementation (code) point of view.point of view.
  • 7.  Ring data structure can be regarded asRing data structure can be regarded as circular Link Listcircular Link List..  In Link List, instead of making last node’sIn Link List, instead of making last node’s next pointer to NULL, we can assign ornext pointer to NULL, we can assign or point it to head node so that it sounds aspoint it to head node so that it sounds as ring data structure as follows.ring data structure as follows. Circular Link List (Ring)Circular Link List (Ring)
  • 8.  Figure showingFigure showing RingRing…..….. BA EC headhead D OROR B A E C headhead D
  • 9. Josephus ProblemJosephus Problem  A case where circularly linked list is handy toA case where circularly linked list is handy to provide the solution of theprovide the solution of the Josephus ProblemJosephus Problem..  Consider there areConsider there are 1010 persons. They would like topersons. They would like to choose achoose a leaderleader..  The way they decide is thatThe way they decide is that all 10 sit in a circleall 10 sit in a circle..  They start a count with personThey start a count with person 11 and go inand go in clockwise direction and skipclockwise direction and skip 3.3. PersonPerson 44 reachedreached is eliminated.is eliminated.  The count starts with the fifth and the next personThe count starts with the fifth and the next person to go is the fourth in count.to go is the fourth in count.  Eventually, a single person remains.Eventually, a single person remains.
  • 20.  Doubly RingDoubly Ring data structure can be regarded asdata structure can be regarded as Circular Doubly Link ListCircular Doubly Link List..  InIn Circular Doubly Link ListCircular Doubly Link List, instead of making last, instead of making last node’snode’s nextnext pointer to NULL, We assign or point itpointer to NULL, We assign or point it toto headhead node. Similarly,node. Similarly, firstfirst (head) node’s(head) node’s previousprevious pointer is pointed to last node in list . sopointer is pointed to last node in list . so that it sounds asthat it sounds as Doubly RingDoubly Ring data structure.data structure. Doubly RingDoubly Ring
  • 21.  Figure showingFigure showing DoublyDoubly RingRing…..….. BA EC headhead D OROR B A E C headhead D
  • 22. Assignment # 3Assignment # 3  Implement aImplement a Josephus ProblemJosephus Problem discusseddiscussed above with following conditions.above with following conditions.  Decide value ofDecide value of MM andand NN at run time.at run time.  AssignAssign numbersnumbers to every node.to every node.  Initiate the problem from node numberInitiate the problem from node number 11..  Submission Due DateSubmission Due Date:: Next week, same dayNext week, same day (In Office Hours)(In Office Hours)