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

PDF
1818 LAB Grocery shopping list linked list inserting at .pdf
PDF
This is the main file include itemh include itemList.pdf
PDF
This assignment and the next (#5) involve design and development of a.pdf
DOCX
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
DOCX
C++ Please write the whole code that is needed for this assignment- wr.docx
PDF
In C++ I need help with this method that Im trying to write fillLi.pdf
PDF
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
PDF
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
1818 LAB Grocery shopping list linked list inserting at .pdf
This is the main file include itemh include itemList.pdf
This assignment and the next (#5) involve design and development of a.pdf
Program 8 C++newproblems.txt12333142013KristinBrewer1032823.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
In C++ I need help with this method that Im trying to write fillLi.pdf
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdf

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

PPT
Mi 103 linked list
PDF
Can somebody solve the TODO parts of the following problem- Thanks D.pdf
PDF
C++ CodeConsider the LinkedList class and the Node class that we s.pdf
PPT
Lec6 mod linked list
PPTX
Linked lists in Data Structure
PDF
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
PDF
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
PDF
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
PPT
Algo>ADT list & linked list
PPTX
Data structure and algorithms chapter three LINKED LIST
PPTX
Lec3-Linked list.pptx
DOCX
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
PPT
Chapter 5 ds
PPTX
Data Structures - Lecture 7 [Linked List]
PPT
Lec6 mod linked list
PPT
dynamicList.ppt
PDF
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
PPT
LINKED LIST IN C++ +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
PDF
File Type cppAdd the following to your linked list of strings pro.pdf
PDF
could you implement this function please, im having issues with it..pdf
Mi 103 linked list
Can somebody solve the TODO parts of the following problem- Thanks D.pdf
C++ CodeConsider the LinkedList class and the Node class that we s.pdf
Lec6 mod linked list
Linked lists in Data Structure
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
Algo>ADT list & linked list
Data structure and algorithms chapter three LINKED LIST
Lec3-Linked list.pptx
#ifndef MYLIST_H_ #define MYLIST_H_#includeiostream #include.docx
Chapter 5 ds
Data Structures - Lecture 7 [Linked List]
Lec6 mod linked list
dynamicList.ppt
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
LINKED LIST IN C++ +2 COMPUTER SCIENCE CBSE AND STATE SYLLABUS
File Type cppAdd the following to your linked list of strings pro.pdf
could you implement this function please, im having issues with it..pdf

More from acmefit (20)

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

Recently uploaded (20)

PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Cell Types and Its function , kingdom of life
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Lesson notes of climatology university.
PDF
Computing-Curriculum for Schools in Ghana
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Institutional Correction lecture only . . .
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Supply Chain Operations Speaking Notes -ICLT Program
Cell Types and Its function , kingdom of life
Renaissance Architecture: A Journey from Faith to Humanism
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
O7-L3 Supply Chain Operations - ICLT Program
Lesson notes of climatology university.
Computing-Curriculum for Schools in Ghana
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Complications of Minimal Access Surgery at WLH
TR - Agricultural Crops Production NC III.pdf
Institutional Correction lecture only . . .

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: