SlideShare a Scribd company logo
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;
}
// Define InsertAtEnd() function that inserts a node
// to the end of the linked list
void InsertAtEnd(string item) {
ItemNode* newNode = new ItemNode(item);
if (nextNodeRef == NULL) {
nextNodeRef = newNode;
} else {
ItemNode* current = nextNodeRef;
while (current->nextNodeRef != NULL) {
current = current->nextNodeRef;
}
current->nextNodeRef = newNode;
}
}
// Get location pointed by nextNodeRef
ItemNode* GetNext() {
return this->nextNodeRef;
}
void PrintNodeData() {
cout << this->item << endl;
}
};
int main() {
int numItems;
cin >> numItems;
ItemNode head;
ItemNode* current = &head;
for (int i = 0; i < numItems; i++) {
string item;
cin >> item;
current->InsertAtEnd(item);
current = current->GetNext();
}
current = head.GetNext();
while (current != NULL) {
current->PrintNodeData();
current = current->GetNext();
}
return 0;
}
main.cpp (only for viewing)
#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!
18.18 LAB: Grocery shopping list (linked list: inserting at the end of a list) Given main0, 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: begin{tabular}{|l} hline 4 Kale Lettuce
Carrots Peanuts end{tabular} 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:

More Related Content

Similar to ItemNodeh include ltiostreamgt include ltstring.pdf

In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
fantoosh1
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklistritu1806
 
Can you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdfCan you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdf
FashionBoutiquedelhi
 
Implement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfImplement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdf
udit652068
 
Linked lists
Linked listsLinked lists
Linked lists
George Scott IV
 
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
 
How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdf
arihantelehyb
 
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdf
fastechsrv
 
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdfAnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
anwarsadath111
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
BrianGHiNewmanv
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdf
connellalykshamesb60
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03Nasir Mehmood
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
anton291
 
#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx
ajoy21
 
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
 
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
FOREVERPRODUCTCHD
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdf
deepua8
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
JUSTSTYLISH3B2MOHALI
 

Similar to ItemNodeh include ltiostreamgt include ltstring.pdf (20)

In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
PathOfMostResistance
PathOfMostResistancePathOfMostResistance
PathOfMostResistance
 
Can you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdfCan you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdf
 
Implement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfImplement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdf
 
Linked lists
Linked listsLinked lists
Linked lists
 
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
 
How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdf
 
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdf
 
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdfAnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdf
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
 
#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.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
Write a program to find the number of comparisons using the binary se.docx
 
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdf
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 

More from acmefit

What can we say about these results Smokers have a nonstat.pdf
What can we say about these results Smokers have a nonstat.pdfWhat can we say about these results Smokers have a nonstat.pdf
What can we say about these results Smokers have a nonstat.pdf
acmefit
 
We use the recursion xixi1+i1iN We use 00 You need to o.pdf
We use the recursion xixi1+i1iN We use 00 You need to o.pdfWe use the recursion xixi1+i1iN We use 00 You need to o.pdf
We use the recursion xixi1+i1iN We use 00 You need to o.pdf
acmefit
 
The lifespan of the Ebola virus on flat dry surfaces has a n.pdf
The lifespan of the Ebola virus on flat dry surfaces has a n.pdfThe lifespan of the Ebola virus on flat dry surfaces has a n.pdf
The lifespan of the Ebola virus on flat dry surfaces has a n.pdf
acmefit
 
Struter Partnership tiene un capital total de socios de 460.pdf
Struter Partnership tiene un capital total de socios de 460.pdfStruter Partnership tiene un capital total de socios de 460.pdf
Struter Partnership tiene un capital total de socios de 460.pdf
acmefit
 
Question 10 Which of the following cannot be said regardin.pdf
Question 10  Which of the following cannot be said regardin.pdfQuestion 10  Which of the following cannot be said regardin.pdf
Question 10 Which of the following cannot be said regardin.pdf
acmefit
 
Q5 5 marks For a natural number e let We denote the domai.pdf
Q5 5 marks For a natural number e let We denote the domai.pdfQ5 5 marks For a natural number e let We denote the domai.pdf
Q5 5 marks For a natural number e let We denote the domai.pdf
acmefit
 
PF1224A Journalizing withdrawal of cash from partnership .pdf
PF1224A Journalizing withdrawal of cash from partnership .pdfPF1224A Journalizing withdrawal of cash from partnership .pdf
PF1224A Journalizing withdrawal of cash from partnership .pdf
acmefit
 
Please answer the 3 questions below thank you in advance Wh.pdf
Please answer the 3 questions below thank you in advance Wh.pdfPlease answer the 3 questions below thank you in advance Wh.pdf
Please answer the 3 questions below thank you in advance Wh.pdf
acmefit
 
please solve this Operators in the same row have the same pr.pdf
please solve this Operators in the same row have the same pr.pdfplease solve this Operators in the same row have the same pr.pdf
please solve this Operators in the same row have the same pr.pdf
acmefit
 
a Suppose R is a partial order over set A Prove or disprov.pdf
a Suppose R is a partial order over set A Prove or disprov.pdfa Suppose R is a partial order over set A Prove or disprov.pdf
a Suppose R is a partial order over set A Prove or disprov.pdf
acmefit
 
please help me with the case study Read the case study .pdf
please help me with the case study      Read the case study .pdfplease help me with the case study      Read the case study .pdf
please help me with the case study Read the case study .pdf
acmefit
 
Note Use the Tax Tables to calculate the answers to the pro.pdf
Note Use the Tax Tables to calculate the answers to the pro.pdfNote Use the Tax Tables to calculate the answers to the pro.pdf
Note Use the Tax Tables to calculate the answers to the pro.pdf
acmefit
 
Mayu is responsible for the security of her companys server.pdf
Mayu is responsible for the security of her companys server.pdfMayu is responsible for the security of her companys server.pdf
Mayu is responsible for the security of her companys server.pdf
acmefit
 
Country Financial a financial services company uses survey.pdf
Country Financial a financial services company uses survey.pdfCountry Financial a financial services company uses survey.pdf
Country Financial a financial services company uses survey.pdf
acmefit
 
Consulte la tabla a continuacin que muestra los datos de lo.pdf
Consulte la tabla a continuacin que muestra los datos de lo.pdfConsulte la tabla a continuacin que muestra los datos de lo.pdf
Consulte la tabla a continuacin que muestra los datos de lo.pdf
acmefit
 
I cant seem to figure out what I am doing wrong in my PyCha.pdf
I cant seem to figure out what I am doing wrong in my PyCha.pdfI cant seem to figure out what I am doing wrong in my PyCha.pdf
I cant seem to figure out what I am doing wrong in my PyCha.pdf
acmefit
 
fill in the blank What is incorrect about an SCorp a Owne.pdf
fill in the blank What is incorrect about an SCorp a Owne.pdffill in the blank What is incorrect about an SCorp a Owne.pdf
fill in the blank What is incorrect about an SCorp a Owne.pdf
acmefit
 
An estimated regression equation was developed to predict th.pdf
An estimated regression equation was developed to predict th.pdfAn estimated regression equation was developed to predict th.pdf
An estimated regression equation was developed to predict th.pdf
acmefit
 
Far from being rigid and inflexible the doctrine of precede.pdf
Far from being rigid and inflexible the doctrine of precede.pdfFar from being rigid and inflexible the doctrine of precede.pdf
Far from being rigid and inflexible the doctrine of precede.pdf
acmefit
 
Exhibit Multiplier The marginal propensity to consume is 0.pdf
Exhibit Multiplier The marginal propensity to consume is 0.pdfExhibit Multiplier The marginal propensity to consume is 0.pdf
Exhibit Multiplier The marginal propensity to consume is 0.pdf
acmefit
 

More from acmefit (20)

What can we say about these results Smokers have a nonstat.pdf
What can we say about these results Smokers have a nonstat.pdfWhat can we say about these results Smokers have a nonstat.pdf
What can we say about these results Smokers have a nonstat.pdf
 
We use the recursion xixi1+i1iN We use 00 You need to o.pdf
We use the recursion xixi1+i1iN We use 00 You need to o.pdfWe use the recursion xixi1+i1iN We use 00 You need to o.pdf
We use the recursion xixi1+i1iN We use 00 You need to o.pdf
 
The lifespan of the Ebola virus on flat dry surfaces has a n.pdf
The lifespan of the Ebola virus on flat dry surfaces has a n.pdfThe lifespan of the Ebola virus on flat dry surfaces has a n.pdf
The lifespan of the Ebola virus on flat dry surfaces has a n.pdf
 
Struter Partnership tiene un capital total de socios de 460.pdf
Struter Partnership tiene un capital total de socios de 460.pdfStruter Partnership tiene un capital total de socios de 460.pdf
Struter Partnership tiene un capital total de socios de 460.pdf
 
Question 10 Which of the following cannot be said regardin.pdf
Question 10  Which of the following cannot be said regardin.pdfQuestion 10  Which of the following cannot be said regardin.pdf
Question 10 Which of the following cannot be said regardin.pdf
 
Q5 5 marks For a natural number e let We denote the domai.pdf
Q5 5 marks For a natural number e let We denote the domai.pdfQ5 5 marks For a natural number e let We denote the domai.pdf
Q5 5 marks For a natural number e let We denote the domai.pdf
 
PF1224A Journalizing withdrawal of cash from partnership .pdf
PF1224A Journalizing withdrawal of cash from partnership .pdfPF1224A Journalizing withdrawal of cash from partnership .pdf
PF1224A Journalizing withdrawal of cash from partnership .pdf
 
Please answer the 3 questions below thank you in advance Wh.pdf
Please answer the 3 questions below thank you in advance Wh.pdfPlease answer the 3 questions below thank you in advance Wh.pdf
Please answer the 3 questions below thank you in advance Wh.pdf
 
please solve this Operators in the same row have the same pr.pdf
please solve this Operators in the same row have the same pr.pdfplease solve this Operators in the same row have the same pr.pdf
please solve this Operators in the same row have the same pr.pdf
 
a Suppose R is a partial order over set A Prove or disprov.pdf
a Suppose R is a partial order over set A Prove or disprov.pdfa Suppose R is a partial order over set A Prove or disprov.pdf
a Suppose R is a partial order over set A Prove or disprov.pdf
 
please help me with the case study Read the case study .pdf
please help me with the case study      Read the case study .pdfplease help me with the case study      Read the case study .pdf
please help me with the case study Read the case study .pdf
 
Note Use the Tax Tables to calculate the answers to the pro.pdf
Note Use the Tax Tables to calculate the answers to the pro.pdfNote Use the Tax Tables to calculate the answers to the pro.pdf
Note Use the Tax Tables to calculate the answers to the pro.pdf
 
Mayu is responsible for the security of her companys server.pdf
Mayu is responsible for the security of her companys server.pdfMayu is responsible for the security of her companys server.pdf
Mayu is responsible for the security of her companys server.pdf
 
Country Financial a financial services company uses survey.pdf
Country Financial a financial services company uses survey.pdfCountry Financial a financial services company uses survey.pdf
Country Financial a financial services company uses survey.pdf
 
Consulte la tabla a continuacin que muestra los datos de lo.pdf
Consulte la tabla a continuacin que muestra los datos de lo.pdfConsulte la tabla a continuacin que muestra los datos de lo.pdf
Consulte la tabla a continuacin que muestra los datos de lo.pdf
 
I cant seem to figure out what I am doing wrong in my PyCha.pdf
I cant seem to figure out what I am doing wrong in my PyCha.pdfI cant seem to figure out what I am doing wrong in my PyCha.pdf
I cant seem to figure out what I am doing wrong in my PyCha.pdf
 
fill in the blank What is incorrect about an SCorp a Owne.pdf
fill in the blank What is incorrect about an SCorp a Owne.pdffill in the blank What is incorrect about an SCorp a Owne.pdf
fill in the blank What is incorrect about an SCorp a Owne.pdf
 
An estimated regression equation was developed to predict th.pdf
An estimated regression equation was developed to predict th.pdfAn estimated regression equation was developed to predict th.pdf
An estimated regression equation was developed to predict th.pdf
 
Far from being rigid and inflexible the doctrine of precede.pdf
Far from being rigid and inflexible the doctrine of precede.pdfFar from being rigid and inflexible the doctrine of precede.pdf
Far from being rigid and inflexible the doctrine of precede.pdf
 
Exhibit Multiplier The marginal propensity to consume is 0.pdf
Exhibit Multiplier The marginal propensity to consume is 0.pdfExhibit Multiplier The marginal propensity to consume is 0.pdf
Exhibit Multiplier The marginal propensity to consume is 0.pdf
 

Recently uploaded

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
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
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
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
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
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.
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
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
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
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
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
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
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 

Recently uploaded (20)

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
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
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
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
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
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
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
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
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
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
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
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
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 

ItemNodeh include ltiostreamgt include ltstring.pdf

  • 1. 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; } // Define InsertAtEnd() function that inserts a node // to the end of the linked list void InsertAtEnd(string item) { ItemNode* newNode = new ItemNode(item); if (nextNodeRef == NULL) { nextNodeRef = newNode; } else { ItemNode* current = nextNodeRef; while (current->nextNodeRef != NULL) { current = current->nextNodeRef;
  • 2. } current->nextNodeRef = newNode; } } // Get location pointed by nextNodeRef ItemNode* GetNext() { return this->nextNodeRef; } void PrintNodeData() { cout << this->item << endl; } }; int main() { int numItems; cin >> numItems; ItemNode head; ItemNode* current = &head; for (int i = 0; i < numItems; i++) { string item; cin >> item; current->InsertAtEnd(item); current = current->GetNext(); } current = head.GetNext(); while (current != NULL) { current->PrintNodeData(); current = current->GetNext(); } return 0; } main.cpp (only for viewing) #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;
  • 3. 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! 18.18 LAB: Grocery shopping list (linked list: inserting at the end of a list) Given main0, 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: begin{tabular}{|l} hline 4 Kale Lettuce Carrots Peanuts end{tabular} 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: