SlideShare a Scribd company logo
The Problem
Complete the function printList that accepts a node * (the head of a linked list) as a parameter
and print out the list in the following format:
If the list is empty then the function should print "Empty list".
You should complete the main function to test your printList in, at least, the following cases:
An empty list
A list with exactly one node
A list with more than one node (eg: 100 -> 200 -> 300, as shown above)
//main.cpp
#include
using namespace std;
struct node {
int val;
node *next;
};
void printList(node *head) {
// printList function
}
int main() {
// Test 1: An empty list
node * head = NULL;
printList(head);
// Test 2: A list with exactly one node
// Test 3: A list with more than one node
return 0;
}
Solution
#include
using namespace std;
struct node {
int val;
node *next;
};
void printList(node *head)
{
int i = 0;
if(head == NULL) // if head is NUll it is empty list
{
cout<<" Empty list";
}
while(head != NULL) //while end of the list is not reached
{
cout<<" Node "<val;
head = head->next; // traverse next node
}
}
int main() {
// Test 1: An empty list
cout<<" list with no node";
node *head = NULL;
printList(head);
// Test 2: A list with exactly one node
cout<<" list with one node";
node *node1 = new node; //make new node
node1->val= 100; //assign its value to 100
node1->next = NULL; //assign its next pointer to null
head= node1; // make it the head node as head is null
printList(head); // call printList function
// Test 3: A list with more than one node
cout<<" list with three nodes";
node *node2 = new node;
node2->val= 200;
node2->next = NULL;
node1->next = node2;
node *node3 = new node;
node3->val= 300;
node3->next = NULL;
node2->next = node3;
printList(head);
return 0;
}

More Related Content

Similar to The ProblemComplete the function printList that accepts a node (.pdf

Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
arorastores
 
When we first examined the array based and node based implementations.docx
 When we first examined the array based and node based implementations.docx When we first examined the array based and node based implementations.docx
When we first examined the array based and node based implementations.docx
ajoy21
 
Linked list
Linked list Linked list
Linked list
Arbind Mandal
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
callawaycorb73779
 
Please find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdfPlease find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdf
angelfragranc
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
rohit219406
 
finish the following code based on green line requirement us.pdf
finish the following code based on green line requirement us.pdffinish the following code based on green line requirement us.pdf
finish the following code based on green line requirement us.pdf
ajay1317
 
#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf
aravlitraders2012
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
poblettesedanoree498
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdf
flashfashioncasualwe
 
Ch17
Ch17Ch17
Ch17
Abbott
 
DS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxDS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docx
VeerannaKotagi1
 
I need to implment a function that can reverse a single linked list..pdf
I need to implment a function that can reverse a single linked list..pdfI need to implment a function that can reverse a single linked list..pdf
I need to implment a function that can reverse a single linked list..pdf
rohit219406
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdf
mallik3000
 
please help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdfplease help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdf
aminbijal86
 
#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf
lakshmijewellery
 
c++ Computational Complexity filling in the following three .pdf
c++ Computational Complexity filling in the  following three .pdfc++ Computational Complexity filling in the  following three .pdf
c++ Computational Complexity filling in the following three .pdf
amitbagga0808
 
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfin Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
sauravmanwanicp
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfJava AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdf
ambersushil
 
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
AdrianEBJKingr
 

Similar to The ProblemComplete the function printList that accepts a node (.pdf (20)

Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
 
When we first examined the array based and node based implementations.docx
 When we first examined the array based and node based implementations.docx When we first examined the array based and node based implementations.docx
When we first examined the array based and node based implementations.docx
 
Linked list
Linked list Linked list
Linked list
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
 
Please find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdfPlease find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdf
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
finish the following code based on green line requirement us.pdf
finish the following code based on green line requirement us.pdffinish the following code based on green line requirement us.pdf
finish the following code based on green line requirement us.pdf
 
#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf#include sstream #include linkylist.h #include iostream.pdf
#include sstream #include linkylist.h #include iostream.pdf
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdf
 
Ch17
Ch17Ch17
Ch17
 
DS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxDS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docx
 
I need to implment a function that can reverse a single linked list..pdf
I need to implment a function that can reverse a single linked list..pdfI need to implment a function that can reverse a single linked list..pdf
I need to implment a function that can reverse a single linked list..pdf
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdf
 
please help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdfplease help me in C++Objective Create a singly linked list of num.pdf
please help me in C++Objective Create a singly linked list of num.pdf
 
#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf
 
c++ Computational Complexity filling in the following three .pdf
c++ Computational Complexity filling in the  following three .pdfc++ Computational Complexity filling in the  following three .pdf
c++ Computational Complexity filling in the following three .pdf
 
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfin Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
 
Java AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdfJava AssignmentUsing the ListNode.java file below Write method.pdf
Java AssignmentUsing the ListNode.java file below Write method.pdf
 
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
 

More from fazanmobiles

H&M The Challenges of Global Expansion and the Move to adopt Intern.pdf
H&M The Challenges of Global Expansion and the Move to adopt Intern.pdfH&M The Challenges of Global Expansion and the Move to adopt Intern.pdf
H&M The Challenges of Global Expansion and the Move to adopt Intern.pdf
fazanmobiles
 
C++ ProgrammingYou are to develop a program to read Baseball playe.pdf
C++ ProgrammingYou are to develop a program to read Baseball playe.pdfC++ ProgrammingYou are to develop a program to read Baseball playe.pdf
C++ ProgrammingYou are to develop a program to read Baseball playe.pdf
fazanmobiles
 
Discuss the differences between a lists regular iterator, which su.pdf
Discuss the differences between a lists regular iterator, which su.pdfDiscuss the differences between a lists regular iterator, which su.pdf
Discuss the differences between a lists regular iterator, which su.pdf
fazanmobiles
 
Feasibility is an important issue in security system formulation. Wh.pdf
Feasibility is an important issue in security system formulation. Wh.pdfFeasibility is an important issue in security system formulation. Wh.pdf
Feasibility is an important issue in security system formulation. Wh.pdf
fazanmobiles
 
CopyPaste the sentence into the text box. Then, insert punctuat.pdf
CopyPaste the sentence into the text box. Then, insert punctuat.pdfCopyPaste the sentence into the text box. Then, insert punctuat.pdf
CopyPaste the sentence into the text box. Then, insert punctuat.pdf
fazanmobiles
 
C programming Create a system managing a mini library system. Eve.pdf
C programming Create a system managing a mini library system. Eve.pdfC programming Create a system managing a mini library system. Eve.pdf
C programming Create a system managing a mini library system. Eve.pdf
fazanmobiles
 
estion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdf
estion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdfestion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdf
estion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdf
fazanmobiles
 
Dr. Muehls mother was a nurse and her father was a dairy farmer. S.pdf
Dr. Muehls mother was a nurse and her father was a dairy farmer. S.pdfDr. Muehls mother was a nurse and her father was a dairy farmer. S.pdf
Dr. Muehls mother was a nurse and her father was a dairy farmer. S.pdf
fazanmobiles
 
CHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdf
CHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdfCHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdf
CHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdf
fazanmobiles
 
can Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdf
can Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdfcan Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdf
can Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdf
fazanmobiles
 
An analyst has decided to capitalize the operating leases of Company.pdf
An analyst has decided to capitalize the operating leases of Company.pdfAn analyst has decided to capitalize the operating leases of Company.pdf
An analyst has decided to capitalize the operating leases of Company.pdf
fazanmobiles
 
Why is a visual analysis important in communicating findings in a bu.pdf
Why is a visual analysis important in communicating findings in a bu.pdfWhy is a visual analysis important in communicating findings in a bu.pdf
Why is a visual analysis important in communicating findings in a bu.pdf
fazanmobiles
 
what usually happens to autoimmune antibody-producing clones dur.pdf
what usually happens to autoimmune antibody-producing clones dur.pdfwhat usually happens to autoimmune antibody-producing clones dur.pdf
what usually happens to autoimmune antibody-producing clones dur.pdf
fazanmobiles
 
Why platinum and its compounds display a variety of colorSoluti.pdf
Why platinum and its compounds display a variety of colorSoluti.pdfWhy platinum and its compounds display a variety of colorSoluti.pdf
Why platinum and its compounds display a variety of colorSoluti.pdf
fazanmobiles
 
What is Vertical versus horizontal integration in healthcare W.pdf
What is Vertical versus horizontal integration in healthcare W.pdfWhat is Vertical versus horizontal integration in healthcare W.pdf
What is Vertical versus horizontal integration in healthcare W.pdf
fazanmobiles
 
What is the role of the financial system Name and describe two mark.pdf
What is the role of the financial system Name and describe two mark.pdfWhat is the role of the financial system Name and describe two mark.pdf
What is the role of the financial system Name and describe two mark.pdf
fazanmobiles
 
What is the difference between a paired artery and an unpaired arter.pdf
What is the difference between a paired artery and an unpaired arter.pdfWhat is the difference between a paired artery and an unpaired arter.pdf
What is the difference between a paired artery and an unpaired arter.pdf
fazanmobiles
 
What has Microsoft improved in Windows Server 2012 when it comes to .pdf
What has Microsoft improved in Windows Server 2012 when it comes to .pdfWhat has Microsoft improved in Windows Server 2012 when it comes to .pdf
What has Microsoft improved in Windows Server 2012 when it comes to .pdf
fazanmobiles
 
What are the steps for developing Developing a Project Scope Stateme.pdf
What are the steps for developing Developing a Project Scope Stateme.pdfWhat are the steps for developing Developing a Project Scope Stateme.pdf
What are the steps for developing Developing a Project Scope Stateme.pdf
fazanmobiles
 
True or False Questions1) Good technology transfer between pr.pdf
True or False Questions1) Good technology transfer between pr.pdfTrue or False Questions1) Good technology transfer between pr.pdf
True or False Questions1) Good technology transfer between pr.pdf
fazanmobiles
 

More from fazanmobiles (20)

H&M The Challenges of Global Expansion and the Move to adopt Intern.pdf
H&M The Challenges of Global Expansion and the Move to adopt Intern.pdfH&M The Challenges of Global Expansion and the Move to adopt Intern.pdf
H&M The Challenges of Global Expansion and the Move to adopt Intern.pdf
 
C++ ProgrammingYou are to develop a program to read Baseball playe.pdf
C++ ProgrammingYou are to develop a program to read Baseball playe.pdfC++ ProgrammingYou are to develop a program to read Baseball playe.pdf
C++ ProgrammingYou are to develop a program to read Baseball playe.pdf
 
Discuss the differences between a lists regular iterator, which su.pdf
Discuss the differences between a lists regular iterator, which su.pdfDiscuss the differences between a lists regular iterator, which su.pdf
Discuss the differences between a lists regular iterator, which su.pdf
 
Feasibility is an important issue in security system formulation. Wh.pdf
Feasibility is an important issue in security system formulation. Wh.pdfFeasibility is an important issue in security system formulation. Wh.pdf
Feasibility is an important issue in security system formulation. Wh.pdf
 
CopyPaste the sentence into the text box. Then, insert punctuat.pdf
CopyPaste the sentence into the text box. Then, insert punctuat.pdfCopyPaste the sentence into the text box. Then, insert punctuat.pdf
CopyPaste the sentence into the text box. Then, insert punctuat.pdf
 
C programming Create a system managing a mini library system. Eve.pdf
C programming Create a system managing a mini library system. Eve.pdfC programming Create a system managing a mini library system. Eve.pdf
C programming Create a system managing a mini library system. Eve.pdf
 
estion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdf
estion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdfestion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdf
estion 47 (1 point) Raul Prebisch, based at the Economic Commission f.pdf
 
Dr. Muehls mother was a nurse and her father was a dairy farmer. S.pdf
Dr. Muehls mother was a nurse and her father was a dairy farmer. S.pdfDr. Muehls mother was a nurse and her father was a dairy farmer. S.pdf
Dr. Muehls mother was a nurse and her father was a dairy farmer. S.pdf
 
CHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdf
CHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdfCHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdf
CHAPTER 19 Reproductive system Disorders 24. List the STD and the org.pdf
 
can Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdf
can Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdfcan Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdf
can Fluorescence Resonance Emission Transfer (FRET) Microscopy be us.pdf
 
An analyst has decided to capitalize the operating leases of Company.pdf
An analyst has decided to capitalize the operating leases of Company.pdfAn analyst has decided to capitalize the operating leases of Company.pdf
An analyst has decided to capitalize the operating leases of Company.pdf
 
Why is a visual analysis important in communicating findings in a bu.pdf
Why is a visual analysis important in communicating findings in a bu.pdfWhy is a visual analysis important in communicating findings in a bu.pdf
Why is a visual analysis important in communicating findings in a bu.pdf
 
what usually happens to autoimmune antibody-producing clones dur.pdf
what usually happens to autoimmune antibody-producing clones dur.pdfwhat usually happens to autoimmune antibody-producing clones dur.pdf
what usually happens to autoimmune antibody-producing clones dur.pdf
 
Why platinum and its compounds display a variety of colorSoluti.pdf
Why platinum and its compounds display a variety of colorSoluti.pdfWhy platinum and its compounds display a variety of colorSoluti.pdf
Why platinum and its compounds display a variety of colorSoluti.pdf
 
What is Vertical versus horizontal integration in healthcare W.pdf
What is Vertical versus horizontal integration in healthcare W.pdfWhat is Vertical versus horizontal integration in healthcare W.pdf
What is Vertical versus horizontal integration in healthcare W.pdf
 
What is the role of the financial system Name and describe two mark.pdf
What is the role of the financial system Name and describe two mark.pdfWhat is the role of the financial system Name and describe two mark.pdf
What is the role of the financial system Name and describe two mark.pdf
 
What is the difference between a paired artery and an unpaired arter.pdf
What is the difference between a paired artery and an unpaired arter.pdfWhat is the difference between a paired artery and an unpaired arter.pdf
What is the difference between a paired artery and an unpaired arter.pdf
 
What has Microsoft improved in Windows Server 2012 when it comes to .pdf
What has Microsoft improved in Windows Server 2012 when it comes to .pdfWhat has Microsoft improved in Windows Server 2012 when it comes to .pdf
What has Microsoft improved in Windows Server 2012 when it comes to .pdf
 
What are the steps for developing Developing a Project Scope Stateme.pdf
What are the steps for developing Developing a Project Scope Stateme.pdfWhat are the steps for developing Developing a Project Scope Stateme.pdf
What are the steps for developing Developing a Project Scope Stateme.pdf
 
True or False Questions1) Good technology transfer between pr.pdf
True or False Questions1) Good technology transfer between pr.pdfTrue or False Questions1) Good technology transfer between pr.pdf
True or False Questions1) Good technology transfer between pr.pdf
 

Recently uploaded

Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 

Recently uploaded (20)

Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 

The ProblemComplete the function printList that accepts a node (.pdf

  • 1. The Problem Complete the function printList that accepts a node * (the head of a linked list) as a parameter and print out the list in the following format: If the list is empty then the function should print "Empty list". You should complete the main function to test your printList in, at least, the following cases: An empty list A list with exactly one node A list with more than one node (eg: 100 -> 200 -> 300, as shown above) //main.cpp #include using namespace std; struct node { int val; node *next; }; void printList(node *head) { // printList function } int main() { // Test 1: An empty list node * head = NULL; printList(head); // Test 2: A list with exactly one node // Test 3: A list with more than one node return 0; } Solution #include using namespace std; struct node { int val; node *next; };
  • 2. void printList(node *head) { int i = 0; if(head == NULL) // if head is NUll it is empty list { cout<<" Empty list"; } while(head != NULL) //while end of the list is not reached { cout<<" Node "<val; head = head->next; // traverse next node } } int main() { // Test 1: An empty list cout<<" list with no node"; node *head = NULL; printList(head); // Test 2: A list with exactly one node cout<<" list with one node"; node *node1 = new node; //make new node node1->val= 100; //assign its value to 100 node1->next = NULL; //assign its next pointer to null head= node1; // make it the head node as head is null printList(head); // call printList function // Test 3: A list with more than one node cout<<" list with three nodes"; node *node2 = new node; node2->val= 200; node2->next = NULL; node1->next = node2; node *node3 = new node; node3->val= 300;
  • 3. node3->next = NULL; node2->next = node3; printList(head); return 0; }