ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/ccscs20/Iterator.hpp
Revision: 8
Committed: 2004-05-14T11:26:01-07:00 (21 years, 1 month ago) by Douglas Thrift
File size: 1091 byte(s)
Log Message:
Alive!

File Contents

# User Rev Content
1 Douglas Thrift 1 // Iterator
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #ifndef _Iterator_hpp_
8     #define _Iterator_hpp_
9    
10 Douglas Thrift 7 #include "NullNode.hpp"
11    
12 Douglas Thrift 1 template<typename Type>
13 Douglas Thrift 7 class DoublyLinkedList;
14    
15     template<typename Type>
16 Douglas Thrift 1 class Iterator
17     {
18     private:
19 Douglas Thrift 7 NullNode<Type>* front;
20     NullNode<Type>* back;
21     NullNode<Type>* here;
22 Douglas Thrift 8 public:
23 Douglas Thrift 7 Iterator(NullNode<Type>* front, NullNode<Type>* back, bool forward = true) : front(front), back(back) { here = forward ? front->getNext() : back->getPrevious(); }
24 Douglas Thrift 8 bool end(void) { return here == back; }
25     bool begin(void) { return here == front; }
26 Douglas Thrift 7 Iterator<Type>& operator++() { here = here->getNext(); return *this; }
27 Douglas Thrift 1 Iterator<Type> operator++(int);
28 Douglas Thrift 7 Iterator<Type>& operator--() { here = here->getPrevious(); return *this; }
29 Douglas Thrift 1 Iterator<Type> operator--(int);
30 Douglas Thrift 7 const Type& operator*() { return here->getValue(); }
31 Douglas Thrift 1 };
32    
33 Douglas Thrift 7 template<typename Type>
34     Iterator<Type> Iterator<Type>::operator++(int)
35     {
36     Iterator itor(*this);
37    
38     ++*this;
39    
40     return itor;
41     }
42    
43     template<typename Type>
44     Iterator<Type> Iterator<Type>::operator--(int)
45     {
46     Iterator itor(*this);
47    
48     --*this;
49    
50     return itor;
51     }
52    
53 Douglas Thrift 1 #endif // _Iterator_hpp_

Properties

Name Value
svn:eol-style native
svn:keywords Id