Set< ElemType >::Iterator Class Reference

#include "set.h"

List of all members.

Public Member Functions

 Iterator ()
bool hasNext ()
ElemType next ()

Friends

class Set


Detailed Description

template<typename ElemType>
class Set< ElemType >::Iterator

This interface defines a nested class within the Set template that provides iterator access to the Set contents.

The idiomatic code for accessing elements using an iterator is to create the iterator from the collection and then enter a loop that calls next() while hasNext() is true, like this:

Set<int>::Iterator itr = set.iterator(); while (itr.hasNext()) int num = itr.next();


Constructor & Destructor Documentation

template<typename ElemType>
Set< ElemType >::Iterator::Iterator (  ) 

The Iterator for Set tracks a pointer to the original Set and a vector containing of the elems that was assembled at the time of iteration creation. The iterator tracks an index into that vector that identifies the next key to return. Each use of next() increments that index, hasNext() verifies the index < the vector's size. This is an example of an "offline" iterator because it copies the set's data, instead of accessing it in-place. This is a bit inefficient (since it copies) but it makes the iterator simplier to write and sidesteps any problems where the client is modifying the set during iteration.


Member Function Documentation

template<typename ElemType>
bool Set< ElemType >::Iterator::hasNext (  ) 

template<typename ElemType>
ElemType Set< ElemType >::Iterator::next (  ) 


Friends And Related Function Documentation

template<typename ElemType>
friend class Set [friend]


The documentation for this class was generated from the following file:
Generated on Mon Feb 12 23:30:08 2007 for CS 106B Libraries by  doxygen 1.5.1