C++ Please #include using namespace std; class IntNode { public: // Constructor IntNode(int dataInit);

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

C++ Please #include using namespace std; class IntNode { public: // Constructor IntNode(int dataInit);

Post by answerhappygod »

C++ Please
C Please Include Iostream Using Namespace Std Class Intnode Public Constructor Intnode Int Datainit 1
C Please Include Iostream Using Namespace Std Class Intnode Public Constructor Intnode Int Datainit 1 (50.19 KiB) Viewed 19 times
#include <iostream>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;};
// ConstructorIntNode::IntNode(int dataInit) { this->dataVal = dataInit; nextNodePtr = nullptr;}
// Get node valueint IntNode::GetNodeData() { return this->dataVal;}
// Get pointer to next nodeIntNode* 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 itemint 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 < 20; ++i) { currNode = new IntNode(i); lastNode->InsertAfter(currNode); lastNode = currNode; }
cout << IndexOf(headNode, 15) <<endl;
return 0;}
Given the IntNode class, define the IndexOf 0 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: head −>14−>191−>22→99 IndexOf(headNode, 22 ) returns 2 . Ex: If the list contains: head −> IndexOf(headNode, 22) returns -1. 397756.2495032.9×3zqy7
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply