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

C++ , add comments to code, show screenshots of code implementation and

#include using namespace std;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!