SlideShare ist ein Scribd-Unternehmen logo
1 von 1
Java-Data structure
A singly linked list of integers has a dummy head node, followed by a node with 8 , followed by
a node with 9 , followed by a node with 1 , and a final node with 3 . h > 8 > 9 > 1 > 3 a) What
does the following code fragment output for the list above? What does it output in general? What
must be true about this list to avoid a runtime error? Node p = head; while (p.next != null) { p =
p n e x t } System.out.println(p.data); b) The following code outputs the sum of all of the values
in the linked list. Explain the unintended side effect that occurs when this code is run. Then
rewrite the code to avoid this side effect. int s = 0 ; while (head != null) { s + = head.data; head
= head.next; } System.out.println(s); Edit View Insert Format Tools Table 12 pt Paragraph B I
A Q T 2

Weitere ähnliche Inhalte

Ähnlich wie Java-Data structure A singly linked list of integers has a dummy head.docx

ExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docxExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docx
gitagrimston
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
maxinesmith73660
 
You are required to write an interactive C program that prompts the .pdf
You are required to write an interactive C program that prompts the .pdfYou are required to write an interactive C program that prompts the .pdf
You are required to write an interactive C program that prompts the .pdf
arrowcomputers8700
 

Ähnlich wie Java-Data structure A singly linked list of integers has a dummy head.docx (19)

Using the code below Part 1 Write a static method called L.pdf
Using the code below Part 1 Write a static method called L.pdfUsing the code below Part 1 Write a static method called L.pdf
Using the code below Part 1 Write a static method called L.pdf
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
 
Adobe
AdobeAdobe
Adobe
 
ExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docxExamName___________________________________MULTIPLE CH.docx
ExamName___________________________________MULTIPLE CH.docx
 
Ch06
Ch06Ch06
Ch06
 
Cd2 [autosaved]
Cd2 [autosaved]Cd2 [autosaved]
Cd2 [autosaved]
 
Cs101 endsem 2014
Cs101 endsem 2014Cs101 endsem 2014
Cs101 endsem 2014
 
miniLesson on the printf() function
miniLesson on the printf() functionminiLesson on the printf() function
miniLesson on the printf() function
 
2. operator
2. operator2. operator
2. operator
 
Session 5-exersice
Session 5-exersiceSession 5-exersice
Session 5-exersice
 
Cheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF CompleteCheat Sheet for Stata v15.00 PDF Complete
Cheat Sheet for Stata v15.00 PDF Complete
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
C Programming Interview Questions
C Programming Interview QuestionsC Programming Interview Questions
C Programming Interview Questions
 
Stata Cheat Sheets (all)
Stata Cheat Sheets (all)Stata Cheat Sheets (all)
Stata Cheat Sheets (all)
 
Write a complete C programme to implement the following sorting algor.docx
 Write a complete C programme to implement the following sorting algor.docx Write a complete C programme to implement the following sorting algor.docx
Write a complete C programme to implement the following sorting algor.docx
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
 
linkedlist.pptx
linkedlist.pptxlinkedlist.pptx
linkedlist.pptx
 
You are required to write an interactive C program that prompts the .pdf
You are required to write an interactive C program that prompts the .pdfYou are required to write an interactive C program that prompts the .pdf
You are required to write an interactive C program that prompts the .pdf
 
Matlab practice
Matlab practiceMatlab practice
Matlab practice
 

Mehr von lucilabevin

Jeffrey has a company with 100 employees- Over the past quarter he has.docx
Jeffrey has a company with 100 employees- Over the past quarter he has.docxJeffrey has a company with 100 employees- Over the past quarter he has.docx
Jeffrey has a company with 100 employees- Over the past quarter he has.docx
lucilabevin
 
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docx
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docxJane- who is married to Stuart- and Betty- a divorced single parent- h.docx
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docx
lucilabevin
 
Introduction to Pest Biology Lab Manual- Try to complete this matching.docx
Introduction to Pest Biology Lab Manual- Try to complete this matching.docxIntroduction to Pest Biology Lab Manual- Try to complete this matching.docx
Introduction to Pest Biology Lab Manual- Try to complete this matching.docx
lucilabevin
 

Mehr von lucilabevin (20)

JKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docx
JKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docxJKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docx
JKCorp- was listed in the US- sock marke- and isued lever 2 ADR- Whot.docx
 
Jeffrey has a company with 100 employees- Over the past quarter he has.docx
Jeffrey has a company with 100 employees- Over the past quarter he has.docxJeffrey has a company with 100 employees- Over the past quarter he has.docx
Jeffrey has a company with 100 employees- Over the past quarter he has.docx
 
JCL Inc- is a major chip manufacturing firm that sells its products to (3).docx
JCL Inc- is a major chip manufacturing firm that sells its products to (3).docxJCL Inc- is a major chip manufacturing firm that sells its products to (3).docx
JCL Inc- is a major chip manufacturing firm that sells its products to (3).docx
 
Java-Data structure Write a method that reverses the order of elemen.docx
Java-Data structure   Write a method that reverses the order of elemen.docxJava-Data structure   Write a method that reverses the order of elemen.docx
Java-Data structure Write a method that reverses the order of elemen.docx
 
JAVA please How do we implement a circular array Create an array of si.docx
JAVA please How do we implement a circular array Create an array of si.docxJAVA please How do we implement a circular array Create an array of si.docx
JAVA please How do we implement a circular array Create an array of si.docx
 
java Implement an algorithm to find the nth to the last element of a s.docx
java Implement an algorithm to find the nth to the last element of a s.docxjava Implement an algorithm to find the nth to the last element of a s.docx
java Implement an algorithm to find the nth to the last element of a s.docx
 
Jarrod became the father of triplets on June 20- On what date is he.docx
Jarrod became the father of triplets on June 20-   On what date is he.docxJarrod became the father of triplets on June 20-   On what date is he.docx
Jarrod became the father of triplets on June 20- On what date is he.docx
 
Janelle is a sixth-grade student who experiences hearing loss- When Ja.docx
Janelle is a sixth-grade student who experiences hearing loss- When Ja.docxJanelle is a sixth-grade student who experiences hearing loss- When Ja.docx
Janelle is a sixth-grade student who experiences hearing loss- When Ja.docx
 
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docx
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docxJane- who is married to Stuart- and Betty- a divorced single parent- h.docx
Jane- who is married to Stuart- and Betty- a divorced single parent- h.docx
 
It is the responsibility of the stakeholders to identify themselves to.docx
It is the responsibility of the stakeholders to identify themselves to.docxIt is the responsibility of the stakeholders to identify themselves to.docx
It is the responsibility of the stakeholders to identify themselves to.docx
 
Isabei Briggs Myers was a pioneer in the study of personality types- T.docx
Isabei Briggs Myers was a pioneer in the study of personality types- T.docxIsabei Briggs Myers was a pioneer in the study of personality types- T.docx
Isabei Briggs Myers was a pioneer in the study of personality types- T.docx
 
Issue Materiality is to Sustainability Materiality as Stakeholder Mana.docx
Issue Materiality is to Sustainability Materiality as Stakeholder Mana.docxIssue Materiality is to Sustainability Materiality as Stakeholder Mana.docx
Issue Materiality is to Sustainability Materiality as Stakeholder Mana.docx
 
Inflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docx
Inflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docxInflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docx
Inflammatory bowel disease (IBD) is an autoimmune disorder impacting t.docx
 
is often used for interaction structure prediction)- Questions for Dis.docx
is often used for interaction structure prediction)- Questions for Dis.docxis often used for interaction structure prediction)- Questions for Dis.docx
is often used for interaction structure prediction)- Questions for Dis.docx
 
Ip Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docx
Ip Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docxIp Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docx
Ip Task- Study- mor rests e car for en ogroed pobiod oi The bemaked on.docx
 
Introduction- Take this quiz to get a quick check on your understandin.docx
Introduction- Take this quiz to get a quick check on your understandin.docxIntroduction- Take this quiz to get a quick check on your understandin.docx
Introduction- Take this quiz to get a quick check on your understandin.docx
 
Introduction to Minerals and Rocks A large segment of geology is the s.docx
Introduction to Minerals and Rocks A large segment of geology is the s.docxIntroduction to Minerals and Rocks A large segment of geology is the s.docx
Introduction to Minerals and Rocks A large segment of geology is the s.docx
 
Introduction to Pest Biology Lab Manual- Try to complete this matching.docx
Introduction to Pest Biology Lab Manual- Try to complete this matching.docxIntroduction to Pest Biology Lab Manual- Try to complete this matching.docx
Introduction to Pest Biology Lab Manual- Try to complete this matching.docx
 
In which organisms a part of the genetic code has alternative reading-.docx
In which organisms a part of the genetic code has alternative reading-.docxIn which organisms a part of the genetic code has alternative reading-.docx
In which organisms a part of the genetic code has alternative reading-.docx
 
intermediate accounting II CH 14 Question 1- Early extinguishment of d.docx
intermediate accounting II CH 14 Question 1- Early extinguishment of d.docxintermediate accounting II CH 14 Question 1- Early extinguishment of d.docx
intermediate accounting II CH 14 Question 1- Early extinguishment of d.docx
 

Kürzlich hochgeladen

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Kürzlich hochgeladen (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 

Java-Data structure A singly linked list of integers has a dummy head.docx

  • 1. Java-Data structure A singly linked list of integers has a dummy head node, followed by a node with 8 , followed by a node with 9 , followed by a node with 1 , and a final node with 3 . h > 8 > 9 > 1 > 3 a) What does the following code fragment output for the list above? What does it output in general? What must be true about this list to avoid a runtime error? Node p = head; while (p.next != null) { p = p n e x t } System.out.println(p.data); b) The following code outputs the sum of all of the values in the linked list. Explain the unintended side effect that occurs when this code is run. Then rewrite the code to avoid this side effect. int s = 0 ; while (head != null) { s + = head.data; head = head.next; } System.out.println(s); Edit View Insert Format Tools Table 12 pt Paragraph B I A Q T 2