SlideShare a Scribd company logo
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

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
ajoy21
 
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 - 3ecomputernotes
 
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
 
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
fashiongallery1
 
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
 
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
info334223
 
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
info334223
 
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
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
 
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
info334223
 
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
info334223
 
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
info334223
 
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
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
 
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
info334223
 
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
info334223
 
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
info334223
 
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
info334223
 
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
info334223
 
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
info334223
 
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
info334223
 
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
info334223
 
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
info334223
 
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
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

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
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
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
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
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
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
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
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
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
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
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
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
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
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
 
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.
 

Recently uploaded (20)

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
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
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
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...
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.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 Á...
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
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...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
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
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
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
 

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!