Source of LinkedIterator.h


  1: //  Created by Frank M. Carrano and Tim Henry.
  2: //  Copyright (c) 2013 __Pearson Education__. All rights reserved.

  4: /** ADT list: Link-based implementation.
  5:     Listing C6-1.
  6:     @file LinkedIterator.h */

  8: #ifndef _LINKED_ITERATOR
  9: #define _LINKED_ITERATOR

 11: #include <iterator>
 12: #include "Node.h"

 14: using namespace std;

 16: template<class ItemType>
 17: class LinkedList;

 19: template <class ItemType>
 20: class LinkedIterator : public iterator<input_iterator_tag, int>
 21: {
 22: private:
 23:    // ADT associated with iterator
 24:    const LinkedList<ItemType>* containerPtr;
 25:    
 26:    // Current location in collection
 27:    Node<ItemType>* currentItemPtr;
 28:    
 29: public:
 30:    LinkedIterator(const LinkedList<ItemType>* someList,
 31:                   Node<ItemType>* nodePtr);
 32:    
 33:    /** Dereferencing operator overload.
 34:     @return The item at the position referenced by iterator. */
 35:    const ItemType operator*();
 36:    
 37:    /** Prefix increment operator overload.
 38:     @return  The iterator referencing the next position in the list. */
 39:    LinkedIterator<ItemType> operator++();
 40:    
 41:    /** Equality operator overload.
 42:     @param LinkedList  The iterator for comparison.
 43:     @return  True if this iterator references the same list and
 44:        the same position as rightHandSide, false otherwise. */    
 45:     bool operator==(const LinkedIterator<ItemType>& rightHandSide) const;
 46:    
 47:     /** Inequality operator overload.
 48:      @param LinkedList  The iterator for comparison.
 49:      @return  True if this iterator does not reference the same
 50:         list and the same position as rightHandSide, false otherwise. */
 51:    bool operator!=(const LinkedIterator<ItemType>& rightHandSide) const;
 52: }; // end LinkedIterator

 54: #include "LinkedIterator.cpp"
 55: #endif