Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In C + + , and make sure that the output is exactly as shown! 1 0 . 2 4 CIST 2 3 6 2
In C and make sure that the output is exactly as shown!
CIST 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:
Kale
Lettuce
Carrots
Peanuts
where 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:
Kale
Lettuce
Carrots
Peanuts
Here is the code that must be modified:
ItemNode.h:
#include
#include
using namespace std;
class ItemNode
private:
string item;
ItemNode nextNodeRef;
public:
Constructor
ItemNode
item ;
nextNodeRef NULL;
Constructor
ItemNodestring itemInit
thisitem itemInit;
thisnextNodeRef NULL;
Constructor
ItemNodestring itemInit, ItemNode nextLoc
thisitem itemInit;
thisnextNodeRef nextLoc;
Insert node after this node.
void InsertAfterItemNode &nodeLoc
ItemNode tmpNext;
tmpNext thisnextNodeRef;
thisnextNodeRef &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 thisnextNodeRef;
void PrintNodeData
cout thisitem endl;
;
The following code cannot be modified:
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 ; i input; i
cin item;
currNode new ItemNodeitem;
lastNodeInsertAtEndcurrNode;
lastNode currNode;
Print linked list
currNode headNodeGetNext;
while currNode NULL
currNodePrintNodeData;
currNode currNodeGetNext;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started