SlideShare a Scribd company logo
1 of 12
Header, Circular and Two-way
Linked Lists
Header Linked Lists
• Header linked list is a linked list which always contains a special
node called the Header Node, at the beginning of the list.
• It has two types:
a) Grounded Header List
Last Node Contains the NULL Pointer.
b) Circular Header List
Last Node Points Back to the Header Node.
2
Header linked list
Grounded Header linked list Circular Header linked list
Grounded Header Linked List
• A grounded header list is a header list where the last
node contains the null pointer.
• The term “grounded” comes from the fact that many
texts use the electrical ground symbol to indicate the
null pointer.
Header Node
Start
Figure: Grounded Header Link List
Circular Header Linked List
• A circular header linked list is a header list where the last
node points back to the header node.
• START always points to the header node.
• LINK[START] = NULL means grounded header list is empty.
• LINK[START] = START indicates that a circular header list is
empty.
Header Node
Figure: Circular Header Link List
Start
Benefits of using Circular Header List
• The null pointer is not used, and hence pointers contain valid
addresses.
• Every (ordinary) node has a predecessor, so the first node
may not require a special case.
Traversing a Circular Header List
Let LIST be a circular header list in memory. This algorithm traverses list,
applying an operation PROCESS to each element of LIST. The variable
PTR points to the node currently being processed.
1. Set PTR := LINK[START]. [Initializes pointer PTR.]
2. Repeat Steps 3 and 4 while PTR != START.
3. Apply PROCESS to INFO[PTR].
4. Set PTR := LINK[PTR]. [PTR now points to the next node.]
[End of Step 2 loop.]
5. Exit.
Searching in circular header list
SRCHHL(INFO,LINK,START,ITEM,LOC)
1 Set PTR=LINK[START]
2 Repeat while INFO[PTR]!=ITEM and PTR!=START
Set PTR=LINK[PTR]
3 if INFO[PTR]=ITEM, then
Set LOC=PTR
Else Set LOC=NULL
4 EXIT
Two-way lists
• A two-way list is a linear collection of data elements,
called nodes, where each node N is divided into three
parts:
– Information field
– Forward Link which points to the next node
– Backward Link which points to the previous node
• The starting address or the address of first node is stored
in START / FIRST pointer .
• Another pointer can be used to traverse list from end.
This pointer is called END or LAST.
Two-way lists(cont…)
• Every node (except the last node) contains the
address of the next node, and every node (except
the first node) contains the address of the previous
node.
• A two-way list (doubly linked list) can be traversed in
either direction.
Representation of
Two-way lists
Start
X 4 2 10
Last
INFO Field
BACK Pointer
FORE Pointer
X
Inserting
• INST(INFO, FORW, BACK, START, LOCA, LOCB,
ITEM)
1. Set NEW := AVAIL, AVAIL=FORW[AVAIL].
[Allocate memory to the new node.]
2. 3. INFO[NEW] := ITEM.
4. Set FORW[LOCA] := NEW, FORW[NEW] := LOCB,
BACK[LOCB] := NEW, BACK[NEW] := LOCA.
5. Exit.
Deletion
DEL(INFO, FORW, BACK, START, LOC)
1. Set FORW[BACK[LOC]] := FORW[LOC], and
BACK[FORW[LOC]] := BACK[LOC].
2. Free memory.
FREE[LOC].
3. Exit.

More Related Content

What's hot

Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data StructureDharita Chokshi
 
Binary Search
Binary SearchBinary Search
Binary Searchkunj desai
 
Travelling Salesman
Travelling SalesmanTravelling Salesman
Travelling SalesmanShuvojit Kar
 
Event handling
Event handlingEvent handling
Event handlingswapnac12
 
Deletion from single way linked list and search
Deletion from single way linked list and searchDeletion from single way linked list and search
Deletion from single way linked list and searchEstiak Khan
 
Linked list
Linked listLinked list
Linked listeShikshak
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked listFahd Allebdi
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data StructureMeghaj Mallick
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsDrishti Bhalla
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & DeletionAfaq Mansoor Khan
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back trackingTech_MX
 
Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Hasanain Alshadoodee
 

What's hot (20)

Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Binary Search
Binary SearchBinary Search
Binary Search
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 
Travelling Salesman
Travelling SalesmanTravelling Salesman
Travelling Salesman
 
Linked lists
Linked listsLinked lists
Linked lists
 
Arrays
ArraysArrays
Arrays
 
Event handling
Event handlingEvent handling
Event handling
 
Deletion from single way linked list and search
Deletion from single way linked list and searchDeletion from single way linked list and search
Deletion from single way linked list and search
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
Hashing
HashingHashing
Hashing
 
Linked list
Linked listLinked list
Linked list
 
single linked list
single linked listsingle linked list
single linked list
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Stack
StackStack
Stack
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking 
 

Similar to header, circular and two way linked lists

4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)Chandan Singh
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsAakash deep Singhal
 
Dounly linked list
Dounly linked listDounly linked list
Dounly linked listNirmalPandey23
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiSowmya Jyothi
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListManishPrajapati78
 
Linked List
Linked ListLinked List
Linked ListRaaviKapoor
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list Mandeep Singh
 
Data structure and algorithms chapter three LINKED LIST
Data structure and algorithms chapter three LINKED LISTData structure and algorithms chapter three LINKED LIST
Data structure and algorithms chapter three LINKED LISTbinakasehun2026
 
cp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.pptcp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.pptssuser9dd05f
 
Linked list using Dynamic Memory Allocation
Linked list using Dynamic Memory AllocationLinked list using Dynamic Memory Allocation
Linked list using Dynamic Memory Allocationkiran Patel
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked listSumathi Kv
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.pptAlliVinay1
 
Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptxnikhilcse1
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5Kumar
 

Similar to header, circular and two way linked lists (20)

4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithms
 
Dounly linked list
Dounly linked listDounly linked list
Dounly linked list
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
Linked List
Linked ListLinked List
Linked List
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
 
DSModule2.pptx
DSModule2.pptxDSModule2.pptx
DSModule2.pptx
 
unit 2- PPT.pdf
unit 2- PPT.pdfunit 2- PPT.pdf
unit 2- PPT.pdf
 
Data structure and algorithms chapter three LINKED LIST
Data structure and algorithms chapter three LINKED LISTData structure and algorithms chapter three LINKED LIST
Data structure and algorithms chapter three LINKED LIST
 
cp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.pptcp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.ppt
 
Linked list using Dynamic Memory Allocation
Linked list using Dynamic Memory AllocationLinked list using Dynamic Memory Allocation
Linked list using Dynamic Memory Allocation
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
 
Team 10
Team 10Team 10
Team 10
 
Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptx
 
Data structures2
Data structures2Data structures2
Data structures2
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
 
linked_list.pptx
linked_list.pptxlinked_list.pptx
linked_list.pptx
 
Lect 11-12 Zaheer Abbas
Lect 11-12 Zaheer AbbasLect 11-12 Zaheer Abbas
Lect 11-12 Zaheer Abbas
 

More from student

Logic Gates
Logic GatesLogic Gates
Logic Gatesstudent
 
Flipflops and Excitation tables of flipflops
Flipflops and Excitation tables of flipflopsFlipflops and Excitation tables of flipflops
Flipflops and Excitation tables of flipflopsstudent
 
Number Systems
Number SystemsNumber Systems
Number Systemsstudent
 
towers of hanoi
towers of hanoitowers of hanoi
towers of hanoistudent
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structurestudent
 
Number Systems
Number SystemsNumber Systems
Number Systemsstudent
 
binary arithmetic rules
binary arithmetic rulesbinary arithmetic rules
binary arithmetic rulesstudent
 
BCD,GRAY and EXCESS 3 codes
BCD,GRAY and EXCESS 3 codesBCD,GRAY and EXCESS 3 codes
BCD,GRAY and EXCESS 3 codesstudent
 
animals colours numbers idioms
animals colours numbers idiomsanimals colours numbers idioms
animals colours numbers idiomsstudent
 
irregular verbs
irregular verbsirregular verbs
irregular verbsstudent
 
dc generator ece
dc generator ecedc generator ece
dc generator ecestudent
 
INDUCTION MOTOR
INDUCTION MOTORINDUCTION MOTOR
INDUCTION MOTORstudent
 
structure and union
structure and unionstructure and union
structure and unionstudent
 
storage class
storage classstorage class
storage classstudent
 
file handling1
file handling1file handling1
file handling1student
 
direct and indirect band gap
direct and indirect band gapdirect and indirect band gap
direct and indirect band gapstudent
 
hall effect
hall effecthall effect
hall effectstudent
 
optics chapter_07_solution_manual
optics chapter_07_solution_manualoptics chapter_07_solution_manual
optics chapter_07_solution_manualstudent
 
dyneins and kinesins
dyneins and kinesinsdyneins and kinesins
dyneins and kinesinsstudent
 
Structure and function of bacterial cells
Structure and function of bacterial cellsStructure and function of bacterial cells
Structure and function of bacterial cellsstudent
 

More from student (20)

Logic Gates
Logic GatesLogic Gates
Logic Gates
 
Flipflops and Excitation tables of flipflops
Flipflops and Excitation tables of flipflopsFlipflops and Excitation tables of flipflops
Flipflops and Excitation tables of flipflops
 
Number Systems
Number SystemsNumber Systems
Number Systems
 
towers of hanoi
towers of hanoitowers of hanoi
towers of hanoi
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structure
 
Number Systems
Number SystemsNumber Systems
Number Systems
 
binary arithmetic rules
binary arithmetic rulesbinary arithmetic rules
binary arithmetic rules
 
BCD,GRAY and EXCESS 3 codes
BCD,GRAY and EXCESS 3 codesBCD,GRAY and EXCESS 3 codes
BCD,GRAY and EXCESS 3 codes
 
animals colours numbers idioms
animals colours numbers idiomsanimals colours numbers idioms
animals colours numbers idioms
 
irregular verbs
irregular verbsirregular verbs
irregular verbs
 
dc generator ece
dc generator ecedc generator ece
dc generator ece
 
INDUCTION MOTOR
INDUCTION MOTORINDUCTION MOTOR
INDUCTION MOTOR
 
structure and union
structure and unionstructure and union
structure and union
 
storage class
storage classstorage class
storage class
 
file handling1
file handling1file handling1
file handling1
 
direct and indirect band gap
direct and indirect band gapdirect and indirect band gap
direct and indirect band gap
 
hall effect
hall effecthall effect
hall effect
 
optics chapter_07_solution_manual
optics chapter_07_solution_manualoptics chapter_07_solution_manual
optics chapter_07_solution_manual
 
dyneins and kinesins
dyneins and kinesinsdyneins and kinesins
dyneins and kinesins
 
Structure and function of bacterial cells
Structure and function of bacterial cellsStructure and function of bacterial cells
Structure and function of bacterial cells
 

Recently uploaded

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...Pooja Nehwal
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 đź’ž Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 đź’ž Full Nigh...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

header, circular and two way linked lists

  • 1. Header, Circular and Two-way Linked Lists
  • 2. Header Linked Lists • Header linked list is a linked list which always contains a special node called the Header Node, at the beginning of the list. • It has two types: a) Grounded Header List Last Node Contains the NULL Pointer. b) Circular Header List Last Node Points Back to the Header Node. 2 Header linked list Grounded Header linked list Circular Header linked list
  • 3. Grounded Header Linked List • A grounded header list is a header list where the last node contains the null pointer. • The term “grounded” comes from the fact that many texts use the electrical ground symbol to indicate the null pointer. Header Node Start Figure: Grounded Header Link List
  • 4. Circular Header Linked List • A circular header linked list is a header list where the last node points back to the header node. • START always points to the header node. • LINK[START] = NULL means grounded header list is empty. • LINK[START] = START indicates that a circular header list is empty. Header Node Figure: Circular Header Link List Start
  • 5. Benefits of using Circular Header List • The null pointer is not used, and hence pointers contain valid addresses. • Every (ordinary) node has a predecessor, so the first node may not require a special case.
  • 6. Traversing a Circular Header List Let LIST be a circular header list in memory. This algorithm traverses list, applying an operation PROCESS to each element of LIST. The variable PTR points to the node currently being processed. 1. Set PTR := LINK[START]. [Initializes pointer PTR.] 2. Repeat Steps 3 and 4 while PTR != START. 3. Apply PROCESS to INFO[PTR]. 4. Set PTR := LINK[PTR]. [PTR now points to the next node.] [End of Step 2 loop.] 5. Exit.
  • 7. Searching in circular header list SRCHHL(INFO,LINK,START,ITEM,LOC) 1 Set PTR=LINK[START] 2 Repeat while INFO[PTR]!=ITEM and PTR!=START Set PTR=LINK[PTR] 3 if INFO[PTR]=ITEM, then Set LOC=PTR Else Set LOC=NULL 4 EXIT
  • 8. Two-way lists • A two-way list is a linear collection of data elements, called nodes, where each node N is divided into three parts: – Information field – Forward Link which points to the next node – Backward Link which points to the previous node • The starting address or the address of first node is stored in START / FIRST pointer . • Another pointer can be used to traverse list from end. This pointer is called END or LAST.
  • 9. Two-way lists(cont…) • Every node (except the last node) contains the address of the next node, and every node (except the first node) contains the address of the previous node. • A two-way list (doubly linked list) can be traversed in either direction.
  • 10. Representation of Two-way lists Start X 4 2 10 Last INFO Field BACK Pointer FORE Pointer X
  • 11. Inserting • INST(INFO, FORW, BACK, START, LOCA, LOCB, ITEM) 1. Set NEW := AVAIL, AVAIL=FORW[AVAIL]. [Allocate memory to the new node.] 2. 3. INFO[NEW] := ITEM. 4. Set FORW[LOCA] := NEW, FORW[NEW] := LOCB, BACK[LOCB] := NEW, BACK[NEW] := LOCA. 5. Exit.
  • 12. Deletion DEL(INFO, FORW, BACK, START, LOC) 1. Set FORW[BACK[LOC]] := FORW[LOC], and BACK[FORW[LOC]] := BACK[LOC]. 2. Free memory. FREE[LOC]. 3. Exit.