SlideShare a Scribd company logo
1 of 2
Download to read offline
18.18 LAB: Grocery shopping list (linked list: inserting at the end of a list)
Given main(), define an InsertAtEnd() member function in the ItemNode class that adds an
element to the end of a linked list. DO NOT print the dummy head node.
Ex. if the input is:
where 4 is the number of items to be inserted; Kale, Lettuce, Carrots, Peanuts are the names of
the items to be added at the end of the list.
The output is:
ItemNode.h:
#include <iostream>
#include <string>
using namespace std;
class ItemNode {
private:
string item;
ItemNode* nextNodeRef;
public:
// Constructor
ItemNode() {
item = "";
nextNodeRef = NULL;
}
// Constructor
ItemNode(string itemInit) {
this->item = itemInit;
this->nextNodeRef = NULL;
}
// Constructor
ItemNode(string itemInit, ItemNode *nextLoc) {
this->item = itemInit;
this->nextNodeRef = nextLoc;
}
// Insert node after this node.
void InsertAfter(ItemNode &nodeLoc) {
ItemNode* tmpNext;
tmpNext = this->nextNodeRef;
this->nextNodeRef = &nodeLoc;
nodeLoc.nextNodeRef = tmpNext;
}
// TODO: Define InsertAtEnd() function that inserts a node
// to the end of the linked list
// Get location pointed by nextNodeRef
ItemNode* GetNext() {
return this->nextNodeRef;
}
void PrintNodeData() {
cout << this->item << endl;
}
};
main.cpp:
#include "ItemNode.h"
int main() {
ItemNode *headNode; // Create intNode objects
ItemNode *currNode;
ItemNode *lastNode;
string item;
int i;
int input;
// Front of nodes list
headNode = new ItemNode();
lastNode = headNode;
cin >> input;
for (i = 0; i < input; i++) {
cin >> item;
currNode = new ItemNode(item);
lastNode->InsertAtEnd(currNode);
lastNode = currNode;
}
// Print linked list
currNode = headNode->GetNext();
while (currNode != NULL) {
currNode->PrintNodeData();
currNode = currNode->GetNext();
}
}
in c++ please. Thank you!

More Related Content

Similar to 1818 LAB Grocery shopping list linked list inserting at .pdf

Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
maheshkumar12354
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdf
Ian5L3Allanm
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
seoagam1
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
adityastores21
 
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
ganisyedtrd
 
written in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdfwritten in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdf
sravi07
 
-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx
Adamq0DJonese
 
Written in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdfWritten in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdf
sravi07
 
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfWritten in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
sravi07
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docx
cgraciela1
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3
ecomputernotes
 
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docxlab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
DIPESH30
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
fortmdu
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
vishalateen
 
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
 
10- Consider the following data structure used for implementing a link.docx
10- Consider the following data structure used for implementing a link.docx10- Consider the following data structure used for implementing a link.docx
10- Consider the following data structure used for implementing a link.docx
todd991
 
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdfComplete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
rajkumarm401
 

Similar to 1818 LAB Grocery shopping list linked list inserting at .pdf (20)

Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
 
please follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdfplease follow all instructions and answer the inbedded questions- and.pdf
please follow all instructions and answer the inbedded questions- and.pdf
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
 
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
 
written in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdfwritten in c- please answer the 4 questions and write the functions ba.pdf
written in c- please answer the 4 questions and write the functions ba.pdf
 
-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx
 
Written in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdfWritten in C- requires linked lists- Please answer the 4 questions and.pdf
Written in C- requires linked lists- Please answer the 4 questions and.pdf
 
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdfWritten in C- requires linked lists- Please answer the 4 questions and (1).pdf
Written in C- requires linked lists- Please answer the 4 questions and (1).pdf
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docx
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3
 
PathOfMostResistance
PathOfMostResistancePathOfMostResistance
PathOfMostResistance
 
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docxlab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
 
For this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdfFor this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.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
 
10- Consider the following data structure used for implementing a link.docx
10- Consider the following data structure used for implementing a link.docx10- Consider the following data structure used for implementing a link.docx
10- Consider the following data structure used for implementing a link.docx
 
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdfComplete the provided partial C++ Linked List program. Main.cpp is g.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
 

More from info334223

Ethical hacking is the use of hacking tools and techniques t.pdf
Ethical hacking is the use of hacking tools and techniques t.pdfEthical hacking is the use of hacking tools and techniques t.pdf
Ethical hacking is the use of hacking tools and techniques t.pdf
info334223
 
51 Case Study 21 Whom Would You Hire More texttospeech.pdf
51 Case Study 21  Whom Would You Hire More texttospeech.pdf51 Case Study 21  Whom Would You Hire More texttospeech.pdf
51 Case Study 21 Whom Would You Hire More texttospeech.pdf
info334223
 
Aeropuerto Internacional de Denver FONDO Cmo se conviert.pdf
Aeropuerto Internacional de Denver  FONDO  Cmo se conviert.pdfAeropuerto Internacional de Denver  FONDO  Cmo se conviert.pdf
Aeropuerto Internacional de Denver FONDO Cmo se conviert.pdf
info334223
 

More from info334223 (20)

Ethical hacking is the use of hacking tools and techniques t.pdf
Ethical hacking is the use of hacking tools and techniques t.pdfEthical hacking is the use of hacking tools and techniques t.pdf
Ethical hacking is the use of hacking tools and techniques t.pdf
 
Assume Victoria Inc VI has some outstanding bonds that ma.pdf
Assume Victoria Inc VI has some outstanding bonds that ma.pdfAssume Victoria Inc VI has some outstanding bonds that ma.pdf
Assume Victoria Inc VI has some outstanding bonds that ma.pdf
 
At December 312020 Marin Corporation had a deferred tax l.pdf
At December 312020  Marin Corporation had a deferred tax l.pdfAt December 312020  Marin Corporation had a deferred tax l.pdf
At December 312020 Marin Corporation had a deferred tax l.pdf
 
Aratrmaclar E coli tarafndan tipik olarak tketilmeyen bir.pdf
Aratrmaclar E coli tarafndan tipik olarak tketilmeyen bir.pdfAratrmaclar E coli tarafndan tipik olarak tketilmeyen bir.pdf
Aratrmaclar E coli tarafndan tipik olarak tketilmeyen bir.pdf
 
51 Case Study 21 Whom Would You Hire More texttospeech.pdf
51 Case Study 21  Whom Would You Hire More texttospeech.pdf51 Case Study 21  Whom Would You Hire More texttospeech.pdf
51 Case Study 21 Whom Would You Hire More texttospeech.pdf
 
6 A medical practice group consists of nine doctors four w.pdf
6 A medical practice group consists of nine doctors four w.pdf6 A medical practice group consists of nine doctors four w.pdf
6 A medical practice group consists of nine doctors four w.pdf
 
2 Adding Command Now we implement the filecopy command cp .pdf
2 Adding Command Now we implement the filecopy command cp .pdf2 Adding Command Now we implement the filecopy command cp .pdf
2 Adding Command Now we implement the filecopy command cp .pdf
 
1How will you manage building this infrastructure and appli.pdf
1How will you manage building this infrastructure and appli.pdf1How will you manage building this infrastructure and appli.pdf
1How will you manage building this infrastructure and appli.pdf
 
Dr Foleys new type of agriculture that he described as fa.pdf
Dr Foleys new type of agriculture that he described as fa.pdfDr Foleys new type of agriculture that he described as fa.pdf
Dr Foleys new type of agriculture that he described as fa.pdf
 
Aeropuerto Internacional de Denver FONDO Cmo se conviert.pdf
Aeropuerto Internacional de Denver  FONDO  Cmo se conviert.pdfAeropuerto Internacional de Denver  FONDO  Cmo se conviert.pdf
Aeropuerto Internacional de Denver FONDO Cmo se conviert.pdf
 
A sample of size 39 was gathered from high school seniors to.pdf
A sample of size 39 was gathered from high school seniors to.pdfA sample of size 39 was gathered from high school seniors to.pdf
A sample of size 39 was gathered from high school seniors to.pdf
 
While Mary Corens was a student at the University of Tenness.pdf
While Mary Corens was a student at the University of Tenness.pdfWhile Mary Corens was a student at the University of Tenness.pdf
While Mary Corens was a student at the University of Tenness.pdf
 
what is the significance related to reproduction and the sig.pdf
what is the significance related to reproduction and the sig.pdfwhat is the significance related to reproduction and the sig.pdf
what is the significance related to reproduction and the sig.pdf
 
When oxygen is present which pair of processes allow conver.pdf
When oxygen is present which pair of processes allow conver.pdfWhen oxygen is present which pair of processes allow conver.pdf
When oxygen is present which pair of processes allow conver.pdf
 
v f alculete the leogti mad varance of the Criting Phis d.pdf
v f alculete the leogti mad varance of the Criting Phis d.pdfv f alculete the leogti mad varance of the Criting Phis d.pdf
v f alculete the leogti mad varance of the Criting Phis d.pdf
 
423 A survey of 1000 US government employees who have an.pdf
423 A survey of 1000 US government employees who have an.pdf423 A survey of 1000 US government employees who have an.pdf
423 A survey of 1000 US government employees who have an.pdf
 
The following partial information is taken from the comparat.pdf
The following partial information is taken from the comparat.pdfThe following partial information is taken from the comparat.pdf
The following partial information is taken from the comparat.pdf
 
3 Lets suppose the A600 of your 1100 diluted culture is 0.pdf
3 Lets suppose the A600 of your 1100 diluted culture is 0.pdf3 Lets suppose the A600 of your 1100 diluted culture is 0.pdf
3 Lets suppose the A600 of your 1100 diluted culture is 0.pdf
 
Select a business or organization of your choice Choose tw.pdf
Select a business or organization of your choice  Choose tw.pdfSelect a business or organization of your choice  Choose tw.pdf
Select a business or organization of your choice Choose tw.pdf
 
Q1 What is the difference between lossy and lossless Data c.pdf
Q1 What is the difference between lossy and lossless Data c.pdfQ1 What is the difference between lossy and lossless Data c.pdf
Q1 What is the difference between lossy and lossless Data c.pdf
 

Recently uploaded

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
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)
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
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 Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
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
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
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...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
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
 

1818 LAB Grocery shopping list linked list inserting at .pdf

  • 1. 18.18 LAB: Grocery shopping list (linked list: inserting at the end of a list) Given main(), define an InsertAtEnd() member function in the ItemNode class that adds an element to the end of a linked list. DO NOT print the dummy head node. Ex. if the input is: where 4 is the number of items to be inserted; Kale, Lettuce, Carrots, Peanuts are the names of the items to be added at the end of the list. The output is: ItemNode.h: #include <iostream> #include <string> using namespace std; class ItemNode { private: string item; ItemNode* nextNodeRef; public: // Constructor ItemNode() { item = ""; nextNodeRef = NULL; } // Constructor ItemNode(string itemInit) { this->item = itemInit; this->nextNodeRef = NULL; } // Constructor ItemNode(string itemInit, ItemNode *nextLoc) { this->item = itemInit; this->nextNodeRef = nextLoc; } // Insert node after this node. void InsertAfter(ItemNode &nodeLoc) { ItemNode* tmpNext; tmpNext = this->nextNodeRef; this->nextNodeRef = &nodeLoc; nodeLoc.nextNodeRef = tmpNext; } // TODO: Define InsertAtEnd() function that inserts a node // to the end of the linked list
  • 2. // Get location pointed by nextNodeRef ItemNode* GetNext() { return this->nextNodeRef; } void PrintNodeData() { cout << this->item << endl; } }; main.cpp: #include "ItemNode.h" int main() { ItemNode *headNode; // Create intNode objects ItemNode *currNode; ItemNode *lastNode; string item; int i; int input; // Front of nodes list headNode = new ItemNode(); lastNode = headNode; cin >> input; for (i = 0; i < input; i++) { cin >> item; currNode = new ItemNode(item); lastNode->InsertAtEnd(currNode); lastNode = currNode; } // Print linked list currNode = headNode->GetNext(); while (currNode != NULL) { currNode->PrintNodeData(); currNode = currNode->GetNext(); } } in c++ please. Thank you!