Source of getPointerTo.cpp


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

  4: // Returns either a pointer to the node containing a given entry or
  5: // the null pointer if the entry is not in the bag.
  6: template<class ItemType>
  7: Node<ItemType>* LinkedBag<ItemType>::getPointerTo(const ItemType& target,
  8:                                                   Node<ItemType>* curPtr) const
  9: {
 10:    Node<ItemType>* result = nullptr;
 11:    if (curPtr != nullptr)
 12:    {
 13:       if (target== curPtr->getItem())
 14:          result = curPtr;
 15:       else
 16:          result = getPointerTo(target, curPtr->getNext());
 17:    } // end if
 18:    
 19:    return result;
 20: }  // end getPointerTo