Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions