Question
C++ , add comments to code, show screenshots of code implementation and output. See bold text for question #include using namespace std; class IntNode {
C++ , add comments to code, show screenshots of code implementation and output. See bold text for question
#include
class IntNode { public: // Constructor IntNode(int dataInit);
// Get node value int GetNodeData();
// Get pointer to next node IntNode* GetNext();
/* Insert node after this node. Before: this -- next After: this -- node -- next */ void InsertAfter(IntNode* newNode); private: int dataVal; IntNode* nextNodePtr; };
// Constructor IntNode::IntNode(int dataInit) { this->dataVal = dataInit; nextNodePtr = nullptr; }
// Get node value int IntNode::GetNodeData() { return this->dataVal; }
// Get pointer to next node IntNode* IntNode::GetNext() { return this->nextNodePtr; }
/* Insert node after this node. Before: this -- next After: this -- node -- next */ void IntNode::InsertAfter(IntNode* newNode) { IntNode* tempNext = this->nextNodePtr; this->nextNodePtr = newNode; newNode->nextNodePtr = tempNext; }
// Return index of target item int IndexOf(IntNode* headNode, int target) { /* Type your code here. */
int main() { IntNode* headNode = new IntNode(-1); IntNode* currNode; IntNode* lastNode;
// Initiaize head node lastNode = headNode;
// Add nodes to the list for (int i = 0; i InsertAfter(currNode); lastNode = currNode; }
cout
return 0; }
Given the IntNode class, define the IndexOf() function to return the index of parameter target or 1 if not found. Note: The first index after the head node is 0. Ex: If the list contains: head141912299 IndexOf(headNode, 22) returns 2. Ex: If the list contains: head -> IndexOf(headNode, 22) returns -1
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