SlideShare a Scribd company logo
1 of 2
Download to read offline
We would like to build a generic list in such a way that we can start either at the front, or at the
back, and move through the list in either direction. Here is an example of such a list (shown here
with Strings), drawn as an object diagram: Every Deque has a header that consists of the Sentine
L node. Ihis header neld does not change, but the fields within the Sentinel node (that provide the
links to the first and the last item in the Deque) can and will change. Each data Node has two
links, one to the next item in the list and one to the previous item in the list. The Sentinel node is
always present. It also has next and prev fields, which are consistently updated to link to the head
of the list and to the tail of the list, respectively. The Sentinel and Node classes both inherit from
a common superclass (shown below), because the next or prev item after any given node may be
either a data-carrying Node or the Sentinel marking the end of the list. The list shown above has
four data-carrying nodes and the lone sentinel. The empty list has just the Sentinel, and its links
to the first and to the last item just reference the Sentinel node itself. So an empty list would have
the following object diagram:
The list shown above has four data-carrying nodes and the lone sentinel. The empty list has just
the Sentinel, and its links to the first and to the last item just reference the Sentinel node itself. So
an empty list would have the following object diagram: The class diagram for these classes is as
follows:
We have an abstract class ANode T, which can be either a Sentinel T> node or an actual Node T
containing data. We use an abstract class here instead of an interface because we need to share
the next and prev fields. Moreover, because all ANodes are contained and hidden within the
Deque, no external code needs to know about it: they are implementation details rather than a
publicly visibly datatype definition. 8.1 Data definitions and examples - Define the classes
ANode T, Node T, Sentinel T, and Deque T. - For Sentinel, define a constructor that takes zero
arguments, and initializes the next and prev fields of the Sentinel to the Sentinel itself. - For
Node T, define two constructors: the first one takes just a value of type T, initializes the data
field. The next and prev fields would be nutl. The second convenience constructor should take a
value of type T and two ANode nodes, initialize the data field to the given value, initialize the
next and prev fields to the given nodes, and also update the given nodes to refer back to this
node. Throw an IllegalArgumentException in this constructor if either of the given nodes is null.
(You can use if (theNode == null) {} to test for null-ness.) Note carefully the order of the
arguments in this constructor! The order should match the class diagram above; getting the order
wrong will result in oddly "backwards" lists. - For Deque T, define two constructors: one which
takes zero arguments and initializes the header to a new Sentinel T, and another convenience
constructor which takes a particular Sentinel value to use. - Make examples of three lists: the
empty list, a list of Strings with the values ("abc", "bcd", "cde", and "def") shown in the drawing
at the beginning of this problem, and a list with (at least) four values that are not ordered
lexicographically. (Hint: If you've defined your constructors correctly, you shouldn't need to use
any explicit assignment statements in your examples class!) (Make more examples as needed to
test the methods you define.) Name your examples class ExamplesDeque, and your first three
examples deque1, deque2 and deque3.
- Design the method size that counts the number of nodes in a list Deque, not including the
header node. (I.e., just count the Nodes and not the Sentinel.) - Design the method addAtHead
for the class Deque that consumes a value of type T and inserts it at the front of the list. Be sure
to fix up all the links correctly! - Design the method addAtTail for the class Deque that
consumes a value of type T and inserts it at the tail of this list. Again, be sure to fix up all the
links correctly! - Design the method removeFromHead for the class Deque that removes the first
node from this Deque. Throw a RuntimeException if an attempt is made to remove from an
empty list. Be sure to fix up all the links correctly! As with ArrayList's remove method, return
the item that's been removed from the list. - Design the method removeFromTail for the class
Deque that removes the last node from this Deque, analogous to removeFromHead above. Again,
be sure to fix up all the links correctly! - Design the method find for the class Deque that takes an
Predicate and produces the first node in this Deque for which the given predicate returns true. If
the predicate never returns true for any value in the Deque, then the find method should return
the header node in this Deque. (Hint: think carefully about the return type for find!)

More Related Content

Similar to We would like to build a generic list in such a way that we can start.pdf

List Data Structure
List Data StructureList Data Structure
List Data StructureZidny Nafan
 
Data Structure Suppose a singly linked list is implemented with refere.docx
Data Structure Suppose a singly linked list is implemented with refere.docxData Structure Suppose a singly linked list is implemented with refere.docx
Data Structure Suppose a singly linked list is implemented with refere.docxcliftonl1
 
computer notes - Linked list
computer notes - Linked listcomputer notes - Linked list
computer notes - Linked listecomputernotes
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptxssuserd2f031
 
4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1SSE_AndyLi
 
Can somebody solve the TODO parts of the following problem- Thanks D.pdf
Can somebody solve the TODO parts of the following problem- Thanks   D.pdfCan somebody solve the TODO parts of the following problem- Thanks   D.pdf
Can somebody solve the TODO parts of the following problem- Thanks D.pdfvinaythemodel
 
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docxSIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docxedgar6wallace88877
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structuresNiraj Agarwal
 
01-intro_stacks.ppt
01-intro_stacks.ppt01-intro_stacks.ppt
01-intro_stacks.pptsoniya555961
 
hello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxhello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxIsaac9LjWelchq
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked ListsJ.T.A.JONES
 

Similar to We would like to build a generic list in such a way that we can start.pdf (20)

Data structure
Data structureData structure
Data structure
 
List data structure
List data structure List data structure
List data structure
 
List Data Structure
List Data StructureList Data Structure
List Data Structure
 
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
 
computer notes - Linked list
computer notes - Linked listcomputer notes - Linked list
computer notes - Linked list
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
 
4 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart14 chapter3 list_stackqueuepart1
4 chapter3 list_stackqueuepart1
 
Can somebody solve the TODO parts of the following problem- Thanks D.pdf
Can somebody solve the TODO parts of the following problem- Thanks   D.pdfCan somebody solve the TODO parts of the following problem- Thanks   D.pdf
Can somebody solve the TODO parts of the following problem- Thanks D.pdf
 
Q
QQ
Q
 
Lec3
Lec3Lec3
Lec3
 
lists
listslists
lists
 
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docxSIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
SIT221 Data Structures and Algorithms     Trimester 2, 2019 .docx
 
Data Structure
Data StructureData Structure
Data Structure
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 
Lec3
Lec3Lec3
Lec3
 
01-intro_stacks.ppt
01-intro_stacks.ppt01-intro_stacks.ppt
01-intro_stacks.ppt
 
hello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxhello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docx
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 

More from yadavup216

visible mutant () of an unknown gene, which induces tumor metastasis.pdf
 visible mutant () of an unknown gene, which induces tumor metastasis.pdf visible mutant () of an unknown gene, which induces tumor metastasis.pdf
visible mutant () of an unknown gene, which induces tumor metastasis.pdfyadavup216
 
Vaccinations aim to create herd immunity, which means that... I. the .pdf
 Vaccinations aim to create herd immunity, which means that... I. the .pdf Vaccinations aim to create herd immunity, which means that... I. the .pdf
Vaccinations aim to create herd immunity, which means that... I. the .pdfyadavup216
 
Villareals nominal GDP increased from $216 billion to $252 billion .pdf
 Villareals nominal GDP increased from $216 billion to $252 billion .pdf Villareals nominal GDP increased from $216 billion to $252 billion .pdf
Villareals nominal GDP increased from $216 billion to $252 billion .pdfyadavup216
 
Viltareals nominal GDP Increased from $189 billion to $280 billion l.pdf
 Viltareals nominal GDP Increased from $189 billion to $280 billion l.pdf Viltareals nominal GDP Increased from $189 billion to $280 billion l.pdf
Viltareals nominal GDP Increased from $189 billion to $280 billion l.pdfyadavup216
 
Venus is about 2.5� hotter than the Earth primarily because Venus .pdf
 Venus is about 2.5� hotter than the Earth primarily because Venus .pdf Venus is about 2.5� hotter than the Earth primarily because Venus .pdf
Venus is about 2.5� hotter than the Earth primarily because Venus .pdfyadavup216
 
value of a share of Ves stock is clocest to A. 51579 B. $4266 c. 52.pdf
 value of a share of Ves stock is clocest to A. 51579 B. $4266 c. 52.pdf value of a share of Ves stock is clocest to A. 51579 B. $4266 c. 52.pdf
value of a share of Ves stock is clocest to A. 51579 B. $4266 c. 52.pdfyadavup216
 
Villareals nominal GDP increased from $189 billion to $280 billion l.pdf
 Villareals nominal GDP increased from $189 billion to $280 billion l.pdf Villareals nominal GDP increased from $189 billion to $280 billion l.pdf
Villareals nominal GDP increased from $189 billion to $280 billion l.pdfyadavup216
 
Verify that f gives a joint probability density function. Then find t.pdf
 Verify that f gives a joint probability density function. Then find t.pdf Verify that f gives a joint probability density function. Then find t.pdf
Verify that f gives a joint probability density function. Then find t.pdfyadavup216
 
What are the ethical issues facing the company.pdf
 What are the ethical issues facing the company.pdf What are the ethical issues facing the company.pdf
What are the ethical issues facing the company.pdfyadavup216
 
What are the hrogenese 6a1=2=1=4 Pewhy kie tath maiait.pdf
 What are the hrogenese 6a1=2=1=4 Pewhy kie tath maiait.pdf What are the hrogenese 6a1=2=1=4 Pewhy kie tath maiait.pdf
What are the hrogenese 6a1=2=1=4 Pewhy kie tath maiait.pdfyadavup216
 
What are the basic components of the system bus (Select all th.pdf
 What are the basic components of the system bus (Select all th.pdf What are the basic components of the system bus (Select all th.pdf
What are the basic components of the system bus (Select all th.pdfyadavup216
 
What are the allele frequencies in a population for two independent l.pdf
 What are the allele frequencies in a population for two independent l.pdf What are the allele frequencies in a population for two independent l.pdf
What are the allele frequencies in a population for two independent l.pdfyadavup216
 
Weyale, an Isiand in Lake superior, has provided an important study s.pdf
 Weyale, an Isiand in Lake superior, has provided an important study s.pdf Weyale, an Isiand in Lake superior, has provided an important study s.pdf
Weyale, an Isiand in Lake superior, has provided an important study s.pdfyadavup216
 
We want to obtain a sample to estimate a population mean. Based on pr.pdf
 We want to obtain a sample to estimate a population mean. Based on pr.pdf We want to obtain a sample to estimate a population mean. Based on pr.pdf
We want to obtain a sample to estimate a population mean. Based on pr.pdfyadavup216
 
Weston Corporation just paid a dividend of $1.5 a share (i.e., D0=$1..pdf
 Weston Corporation just paid a dividend of $1.5 a share (i.e., D0=$1..pdf Weston Corporation just paid a dividend of $1.5 a share (i.e., D0=$1..pdf
Weston Corporation just paid a dividend of $1.5 a share (i.e., D0=$1..pdfyadavup216
 
Western Michigan Clinic uses client-visits as its measure of activity.pdf
 Western Michigan Clinic uses client-visits as its measure of activity.pdf Western Michigan Clinic uses client-visits as its measure of activity.pdf
Western Michigan Clinic uses client-visits as its measure of activity.pdfyadavup216
 
Weaver Corporation had the following stock issued and outstanding at .pdf
 Weaver Corporation had the following stock issued and outstanding at .pdf Weaver Corporation had the following stock issued and outstanding at .pdf
Weaver Corporation had the following stock issued and outstanding at .pdfyadavup216
 
We use simulator x86.py to study the concurrency with multithreading..pdf
 We use simulator x86.py to study the concurrency with multithreading..pdf We use simulator x86.py to study the concurrency with multithreading..pdf
We use simulator x86.py to study the concurrency with multithreading..pdfyadavup216
 
We dscursed many diAerent ways to evaluate the economy (A) in 12 smte.pdf
 We dscursed many diAerent ways to evaluate the economy (A) in 12 smte.pdf We dscursed many diAerent ways to evaluate the economy (A) in 12 smte.pdf
We dscursed many diAerent ways to evaluate the economy (A) in 12 smte.pdfyadavup216
 
We have three DD statements DD1 DD UNIT =3480,�DD2 DD UNIT =0560.pdf
 We have three DD statements DD1 DD UNIT =3480,�DD2 DD UNIT =0560.pdf We have three DD statements DD1 DD UNIT =3480,�DD2 DD UNIT =0560.pdf
We have three DD statements DD1 DD UNIT =3480,�DD2 DD UNIT =0560.pdfyadavup216
 

More from yadavup216 (20)

visible mutant () of an unknown gene, which induces tumor metastasis.pdf
 visible mutant () of an unknown gene, which induces tumor metastasis.pdf visible mutant () of an unknown gene, which induces tumor metastasis.pdf
visible mutant () of an unknown gene, which induces tumor metastasis.pdf
 
Vaccinations aim to create herd immunity, which means that... I. the .pdf
 Vaccinations aim to create herd immunity, which means that... I. the .pdf Vaccinations aim to create herd immunity, which means that... I. the .pdf
Vaccinations aim to create herd immunity, which means that... I. the .pdf
 
Villareals nominal GDP increased from $216 billion to $252 billion .pdf
 Villareals nominal GDP increased from $216 billion to $252 billion .pdf Villareals nominal GDP increased from $216 billion to $252 billion .pdf
Villareals nominal GDP increased from $216 billion to $252 billion .pdf
 
Viltareals nominal GDP Increased from $189 billion to $280 billion l.pdf
 Viltareals nominal GDP Increased from $189 billion to $280 billion l.pdf Viltareals nominal GDP Increased from $189 billion to $280 billion l.pdf
Viltareals nominal GDP Increased from $189 billion to $280 billion l.pdf
 
Venus is about 2.5� hotter than the Earth primarily because Venus .pdf
 Venus is about 2.5� hotter than the Earth primarily because Venus .pdf Venus is about 2.5� hotter than the Earth primarily because Venus .pdf
Venus is about 2.5� hotter than the Earth primarily because Venus .pdf
 
value of a share of Ves stock is clocest to A. 51579 B. $4266 c. 52.pdf
 value of a share of Ves stock is clocest to A. 51579 B. $4266 c. 52.pdf value of a share of Ves stock is clocest to A. 51579 B. $4266 c. 52.pdf
value of a share of Ves stock is clocest to A. 51579 B. $4266 c. 52.pdf
 
Villareals nominal GDP increased from $189 billion to $280 billion l.pdf
 Villareals nominal GDP increased from $189 billion to $280 billion l.pdf Villareals nominal GDP increased from $189 billion to $280 billion l.pdf
Villareals nominal GDP increased from $189 billion to $280 billion l.pdf
 
Verify that f gives a joint probability density function. Then find t.pdf
 Verify that f gives a joint probability density function. Then find t.pdf Verify that f gives a joint probability density function. Then find t.pdf
Verify that f gives a joint probability density function. Then find t.pdf
 
What are the ethical issues facing the company.pdf
 What are the ethical issues facing the company.pdf What are the ethical issues facing the company.pdf
What are the ethical issues facing the company.pdf
 
What are the hrogenese 6a1=2=1=4 Pewhy kie tath maiait.pdf
 What are the hrogenese 6a1=2=1=4 Pewhy kie tath maiait.pdf What are the hrogenese 6a1=2=1=4 Pewhy kie tath maiait.pdf
What are the hrogenese 6a1=2=1=4 Pewhy kie tath maiait.pdf
 
What are the basic components of the system bus (Select all th.pdf
 What are the basic components of the system bus (Select all th.pdf What are the basic components of the system bus (Select all th.pdf
What are the basic components of the system bus (Select all th.pdf
 
What are the allele frequencies in a population for two independent l.pdf
 What are the allele frequencies in a population for two independent l.pdf What are the allele frequencies in a population for two independent l.pdf
What are the allele frequencies in a population for two independent l.pdf
 
Weyale, an Isiand in Lake superior, has provided an important study s.pdf
 Weyale, an Isiand in Lake superior, has provided an important study s.pdf Weyale, an Isiand in Lake superior, has provided an important study s.pdf
Weyale, an Isiand in Lake superior, has provided an important study s.pdf
 
We want to obtain a sample to estimate a population mean. Based on pr.pdf
 We want to obtain a sample to estimate a population mean. Based on pr.pdf We want to obtain a sample to estimate a population mean. Based on pr.pdf
We want to obtain a sample to estimate a population mean. Based on pr.pdf
 
Weston Corporation just paid a dividend of $1.5 a share (i.e., D0=$1..pdf
 Weston Corporation just paid a dividend of $1.5 a share (i.e., D0=$1..pdf Weston Corporation just paid a dividend of $1.5 a share (i.e., D0=$1..pdf
Weston Corporation just paid a dividend of $1.5 a share (i.e., D0=$1..pdf
 
Western Michigan Clinic uses client-visits as its measure of activity.pdf
 Western Michigan Clinic uses client-visits as its measure of activity.pdf Western Michigan Clinic uses client-visits as its measure of activity.pdf
Western Michigan Clinic uses client-visits as its measure of activity.pdf
 
Weaver Corporation had the following stock issued and outstanding at .pdf
 Weaver Corporation had the following stock issued and outstanding at .pdf Weaver Corporation had the following stock issued and outstanding at .pdf
Weaver Corporation had the following stock issued and outstanding at .pdf
 
We use simulator x86.py to study the concurrency with multithreading..pdf
 We use simulator x86.py to study the concurrency with multithreading..pdf We use simulator x86.py to study the concurrency with multithreading..pdf
We use simulator x86.py to study the concurrency with multithreading..pdf
 
We dscursed many diAerent ways to evaluate the economy (A) in 12 smte.pdf
 We dscursed many diAerent ways to evaluate the economy (A) in 12 smte.pdf We dscursed many diAerent ways to evaluate the economy (A) in 12 smte.pdf
We dscursed many diAerent ways to evaluate the economy (A) in 12 smte.pdf
 
We have three DD statements DD1 DD UNIT =3480,�DD2 DD UNIT =0560.pdf
 We have three DD statements DD1 DD UNIT =3480,�DD2 DD UNIT =0560.pdf We have three DD statements DD1 DD UNIT =3480,�DD2 DD UNIT =0560.pdf
We have three DD statements DD1 DD UNIT =3480,�DD2 DD UNIT =0560.pdf
 

Recently uploaded

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
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
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
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
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
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
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Recently uploaded (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
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
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
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
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
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
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
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"
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 

We would like to build a generic list in such a way that we can start.pdf

  • 1. We would like to build a generic list in such a way that we can start either at the front, or at the back, and move through the list in either direction. Here is an example of such a list (shown here with Strings), drawn as an object diagram: Every Deque has a header that consists of the Sentine L node. Ihis header neld does not change, but the fields within the Sentinel node (that provide the links to the first and the last item in the Deque) can and will change. Each data Node has two links, one to the next item in the list and one to the previous item in the list. The Sentinel node is always present. It also has next and prev fields, which are consistently updated to link to the head of the list and to the tail of the list, respectively. The Sentinel and Node classes both inherit from a common superclass (shown below), because the next or prev item after any given node may be either a data-carrying Node or the Sentinel marking the end of the list. The list shown above has four data-carrying nodes and the lone sentinel. The empty list has just the Sentinel, and its links to the first and to the last item just reference the Sentinel node itself. So an empty list would have the following object diagram: The list shown above has four data-carrying nodes and the lone sentinel. The empty list has just the Sentinel, and its links to the first and to the last item just reference the Sentinel node itself. So an empty list would have the following object diagram: The class diagram for these classes is as follows: We have an abstract class ANode T, which can be either a Sentinel T> node or an actual Node T containing data. We use an abstract class here instead of an interface because we need to share the next and prev fields. Moreover, because all ANodes are contained and hidden within the Deque, no external code needs to know about it: they are implementation details rather than a publicly visibly datatype definition. 8.1 Data definitions and examples - Define the classes ANode T, Node T, Sentinel T, and Deque T. - For Sentinel, define a constructor that takes zero arguments, and initializes the next and prev fields of the Sentinel to the Sentinel itself. - For Node T, define two constructors: the first one takes just a value of type T, initializes the data field. The next and prev fields would be nutl. The second convenience constructor should take a value of type T and two ANode nodes, initialize the data field to the given value, initialize the next and prev fields to the given nodes, and also update the given nodes to refer back to this node. Throw an IllegalArgumentException in this constructor if either of the given nodes is null. (You can use if (theNode == null) {} to test for null-ness.) Note carefully the order of the arguments in this constructor! The order should match the class diagram above; getting the order wrong will result in oddly "backwards" lists. - For Deque T, define two constructors: one which takes zero arguments and initializes the header to a new Sentinel T, and another convenience constructor which takes a particular Sentinel value to use. - Make examples of three lists: the
  • 2. empty list, a list of Strings with the values ("abc", "bcd", "cde", and "def") shown in the drawing at the beginning of this problem, and a list with (at least) four values that are not ordered lexicographically. (Hint: If you've defined your constructors correctly, you shouldn't need to use any explicit assignment statements in your examples class!) (Make more examples as needed to test the methods you define.) Name your examples class ExamplesDeque, and your first three examples deque1, deque2 and deque3. - Design the method size that counts the number of nodes in a list Deque, not including the header node. (I.e., just count the Nodes and not the Sentinel.) - Design the method addAtHead for the class Deque that consumes a value of type T and inserts it at the front of the list. Be sure to fix up all the links correctly! - Design the method addAtTail for the class Deque that consumes a value of type T and inserts it at the tail of this list. Again, be sure to fix up all the links correctly! - Design the method removeFromHead for the class Deque that removes the first node from this Deque. Throw a RuntimeException if an attempt is made to remove from an empty list. Be sure to fix up all the links correctly! As with ArrayList's remove method, return the item that's been removed from the list. - Design the method removeFromTail for the class Deque that removes the last node from this Deque, analogous to removeFromHead above. Again, be sure to fix up all the links correctly! - Design the method find for the class Deque that takes an Predicate and produces the first node in this Deque for which the given predicate returns true. If the predicate never returns true for any value in the Deque, then the find method should return the header node in this Deque. (Hint: think carefully about the return type for find!)