Source of Listing4-2.cpp


  1: //  Created by Frank M. Carrano and Timothy M. Henry.
  2: //  Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.

  4: /** @file Node.cpp 
  5:     Listing 4-2 */
  6: #include "Node.h"

  8: template<class ItemType>
  9: Node<ItemType>::Node() : next(nullptr)
 10: {
 11: } // end default constructor

 13: template<class ItemType>
 14: Node<ItemType>::Node(const ItemType& anItem) : item(anItem), next(nullptr)
 15: {
 16: } // end constructor

 18: template<class ItemType>
 19: Node<ItemType>::Node(const ItemType& anItem, Node<ItemType>* nextNodePtr) :
 20:                 item(anItem), next(nextNodePtr)
 21: {
 22: } // end constructor

 24: template<class ItemType>
 25: void Node<ItemType>::setItem(const ItemType& anItem)
 26: {
 27:    item = anItem;
 28: } // end setItem

 30: template<class ItemType>
 31: void Node<ItemType>::setNext(Node<ItemType>* nextNodePtr)
 32: {
 33:    next = nextNodePtr;
 34: } // end setNext

 36: template<class ItemType>
 37: ItemType Node<ItemType>::getItem() const
 38: {
 39:    return item;
 40: } // end getItem

 42: template<class ItemType>
 43: Node<ItemType>* Node<ItemType>::getNext() const
 44: {
 45:    return next;
 46: } // end getNext