ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/ccscs20/Iterator.hpp
Revision: 13
Committed: 2004-05-15T14:59:28-07:00 (21 years, 1 month ago) by Douglas Thrift
File size: 1143 byte(s)
Log Message:
Take that David!

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 Douglas Thrift 13 Node<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 9 const Type* operator->() { return &here->getValue(); }
32 Douglas Thrift 1 };
33    
34 Douglas Thrift 7 template<typename Type>
35     Iterator<Type> Iterator<Type>::operator++(int)
36     {
37     Iterator itor(*this);
38    
39     ++*this;
40    
41     return itor;
42     }
43    
44     template<typename Type>
45     Iterator<Type> Iterator<Type>::operator--(int)
46     {
47     Iterator itor(*this);
48    
49     --*this;
50    
51     return itor;
52     }
53    
54 Douglas Thrift 1 #endif // _Iterator_hpp_

Properties

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