Question: Node.h /** @file Node.h Listing 4-1 */ #ifndef _NODE #define _NODE template class Node { private: ItemType item; // A data item Node * next;

 Node.h /** @file Node.h Listing 4-1 */ #ifndef _NODE #define _NODE

Node.h

/** @file Node.h Listing 4-1 */ #ifndef _NODE #define _NODE

template class Node { private: ItemType item; // A data item Node* next; // Pointer to next node

public: Node(); Node(const ItemType& anItem); Node(const ItemType& anItem, Node* nextNodePtr); void setItem(const ItemType& anItem); void setNext(Node* nextNodePtr); ItemType getItem() const; Node* getNext() const; }; // end Node

//#include "Node.cpp" #include "Node.h" #include

template Node::Node() : next(nullptr) { } // end default constructor

template Node::Node(const ItemType& anItem) : item(anItem), next(nullptr) { } // end constructor

template Node::Node(const ItemType& anItem, Node* nextNodePtr) : item(anItem), next(nextNodePtr) { } // end constructor

template void Node::setItem(const ItemType& anItem) { item = anItem; } // end setItem

template void Node::setNext(Node* nextNodePtr) { next = nextNodePtr; } // end setNext

template ItemType Node::getItem() const { return item; } // end getItem

template Node* Node::getNext() const { return next; } // end getNext

#endif

Node.cpp

#include "Node.h" #include

template Node::Node() : next(nullptr) { } // end default constructor

template Node::Node(const ItemType& anItem) : item(anItem), next(nullptr) { } // end constructor

template Node::Node(const ItemType& anItem, Node* nextNodePtr) : item(anItem), next(nextNodePtr) { } // end constructor

template void Node::setItem(const ItemType& anItem) { item = anItem; } // end setItem

template void Node::setNext(Node* nextNodePtr) { next = nextNodePtr; } // end setNext

template ItemType Node::getItem() const { return item; } // end getItem

template Node* Node::getNext() const { return next; } // end getNext

A Linked List with Node Class A Linked List with Node Class Write a main program (client program) that creates a linked list as in the following figure. nullptr "ef""gh item next tem next tem next Node.h and Node.cpp must be used to create the list

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!