#ifndef NODE_CLASS #define NODE_CLASS template class Node { private: // next is the address of the following node Node *next; public: // the data is public T data; // constructor Node (const T& item, Node* ptrnext = NULL); // list modification methods void InsertAfter(Node *p); Node *DeleteAfter(void); // obtain the address of the next node Node *NextNode(void) const; }; // constructor. initialize data and pointer members template Node::Node(const T& item, Node* ptrnext) : data(item), next(ptrnext) {} // return value of private member next template Node *Node::NextNode(void) const { return next; } // insert a node p after the current one template void Node::InsertAfter(Node *p) { // p points to successor of the current node, // and current node points to p. p->next = next; next = p; } // delete the node following current and return its address template Node *Node::DeleteAfter(void) { // save address of node to be deleted Node *tempPtr = next; // if there isn't a successor, return NULL if (next == NULL) return NULL; // current node points to successor of tempPtr. next = tempPtr->next; // return the pointer to the unlinked node return tempPtr; } #endif // NODE_CLASS