Data Structures in C++
Public Member Functions | Private Attributes
Iterator< T > Class Template Reference

Object that provides iterative powers to classes composed of Node. More...

#include <Iterator.hpp>

Collaboration diagram for Iterator< T >:

Public Member Functions

 Iterator (Node< T > *n)
 Creates an iterator. More...
 
bool hasNext ()
 Returns whether the iterator has a next value to explore. More...
 
bool hasPrevious ()
 Returns whether the iterator has a previous value to explore. More...
 
next ()
 Go to the next value. More...
 
previous ()
 Go to the previous value. More...
 
current ()
 Get the current value the iterator holds. More...
 

Private Attributes

Node< T > * node
 
bool firstRun = true
 

Detailed Description

template<class T>
class Iterator< T >

Object that provides iterative powers to classes composed of Node.

Author
Douglas De Rizzo Meneghetti (dougl.nosp@m.asri.nosp@m.zzom@.nosp@m.gmai.nosp@m.l.com)
Date
2017-7-5This object provides iterative powers to classes that have Node as their underlying data storage objects.
Template Parameters
TThe type of object the Node inside the Iterator will hold.

Definition at line 13 of file Iterator.hpp.

Constructor & Destructor Documentation

◆ Iterator()

template<class T >
Iterator< T >::Iterator ( Node< T > *  n)
inlineexplicit

Creates an iterator.

Parameters
nThe starting node for the iteration

Definition at line 23 of file Iterator.hpp.

23  {
24  node = n;
25  }
Node< T > * node
Definition: Iterator.hpp:16

Member Function Documentation

◆ current()

template<class T >
T Iterator< T >::current ( )
inline

Get the current value the iterator holds.

Returns
The current value in the iteration

Definition at line 60 of file Iterator.hpp.

60  {
61  return node->getValue();
62  }
Node< T > * node
Definition: Iterator.hpp:16

◆ hasNext()

template<class T >
bool Iterator< T >::hasNext ( )
inline

Returns whether the iterator has a next value to explore.

Returns
True if there is a next value, otherwise false

Definition at line 29 of file Iterator.hpp.

29  {
30  return firstRun and node != NULL or node->getNext() != NULL;
31  }
bool firstRun
Definition: Iterator.hpp:17
Node< T > * node
Definition: Iterator.hpp:16

◆ hasPrevious()

template<class T >
bool Iterator< T >::hasPrevious ( )
inline

Returns whether the iterator has a previous value to explore.

Returns
True if there is a previous value, otherwise false

Definition at line 35 of file Iterator.hpp.

35  {
36  return node->getPrevious() != NULL;
37  }
Node< T > * node
Definition: Iterator.hpp:16

◆ next()

template<class T >
T Iterator< T >::next ( )
inline

Go to the next value.

Returns
The next value in the iteration

Definition at line 41 of file Iterator.hpp.

41  {
42  if (firstRun) {
43  firstRun = ! firstRun;
44  return node->getValue();
45  }
46 
47  node = node->getNext();
48  return node->getValue();
49  }
bool firstRun
Definition: Iterator.hpp:17
Node< T > * node
Definition: Iterator.hpp:16

◆ previous()

template<class T >
T Iterator< T >::previous ( )
inline

Go to the previous value.

Returns
The previous value in the iteration

Definition at line 53 of file Iterator.hpp.

53  {
54  node = node->getNext();
55  return node->getValue();
56  }
Node< T > * node
Definition: Iterator.hpp:16

Field Documentation

◆ firstRun

template<class T >
bool Iterator< T >::firstRun = true
private

Definition at line 17 of file Iterator.hpp.

◆ node

template<class T >
Node<T>* Iterator< T >::node
private

Definition at line 16 of file Iterator.hpp.


The documentation for this class was generated from the following file: