| | | | | next -> |

Implementing class TListIterator < T >

template <typename T>
bool TListIterator<T>::operator == (const TListIterator<T>& I2) const
{
  if (currLink == I2.currLink)
    return 1;
  return 0;
}

template <typename T>
bool TListIterator<T>::operator != (const TListIterator<T>& I2) const
{
  // TBS
}

template <typename T>
TListIterator<T>::TListIterator ()  :  currLink(0)
// construct a null TListIterator 
{}

template <typename T>
TListIterator<T>::TListIterator (const TList<T>& L)
// construct an iterator for L, starting at beginning
{
  Initialize(L);
}

template <typename T>
TListIterator<T>::TListIterator (const TListIterator<T>& I)
   :  currLink(I.currLink)
// copy constructor
{}

template <typename T>
void TListIterator<T>::Initialize (const TList<T>& L)
{
  currLink = L.firstLink;
}

template <typename T>
void TListIterator<T>::rInitialize (const TList<T>& L)
{
  currLink = L.lastLink;
}

template <typename T>
bool TListIterator<T>::Valid () const
// test cursor for validity
{
  return currLink != 0;
}

template <typename T>
T&  TListIterator<T>::Retrieve () const
// Return reference to current t 
// may be used on left side of T::operator=()
// pre:  Valid() 
// code for safety over speed?
{
  if (currLink == 0)
  {
    std::cerr << "** Error: TListIterator:: invalid dereference\n";
    exit (EXIT_FAILURE);
  }
  return currLink->value;
}

template <typename T>
T&  TListIterator<T>::operator * () const
// Return reference to current t
// may be used on left side of T::operator=()
// pre:  Valid() 
// code for speed over safety?
{
  return currLink->value;
}

template <typename T>
TListIterator<T>& TListIterator<T>::operator = (const TListIterator <T> & I)
{
  // TBS
}

template <typename T>
TListIterator<T>& TListIterator<T>::operator ++ ()
// prefix increment
{
  // TBS
}

template <typename T>
TListIterator<T> TListIterator<T>::operator ++ (int)
// postfix increment
{
  // TBS
}

template <typename T>
TListIterator<T>& TListIterator<T>::operator -- ()
// prefix decrement
{
  // TBS
}

template <typename T>
TListIterator<T> TListIterator<T>::operator -- (int)
// postfix decrement
{
  // TBS
}

| next -> | Top of Page | 8. A Generic List Class and Linked Lists - 19 of 19