-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterator.hpp
More file actions
78 lines (62 loc) · 1.39 KB
/
iterator.hpp
File metadata and controls
78 lines (62 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "list.hpp"
#pragma once
#include <iostream>
template <typename T>
class Iterator {
friend class List<T>;
Elem<T> *el;
public:
Iterator(Elem<T> *e): el(e){};
Iterator &operator++ ();
Iterator &operator-- ();
void operator++ (int);
void operator-- (int);
Elem<T> &operator* ();
Elem<T> *operator-> ();
bool operator!= (Iterator const& r);
Iterator &operator= (const Iterator &r);
};
template <typename T>
Iterator<T> &Iterator<T>::operator= (const Iterator<T> &r)
{
if(&r == this)
return *this;
return Iterator(this.info = r.info);
}
//------------------------------------------------------
template <typename T>
Iterator<T> &Iterator<T>::operator++ (){
if(el)
el = el->next;
return *this;
}
template <typename T>
void Iterator<T>::operator++ (int){
if(el)
el = el->next;
}
template <typename T>
Iterator<T> &Iterator<T>::operator-- (){
if(el)
el = el->prev;
return *this;
}
template <typename T>
void Iterator<T>::operator-- (int){
if(el)
el = el->prev;
}
template <typename T>
Elem<T> &Iterator<T>::operator* (){
return *el;
}
template <typename T>
Elem<T> *Iterator<T>::operator-> (){
return el;
}
template <typename T>
bool Iterator<T>::operator!=(Iterator<T> const& r)
{
//std::cout << "op!=" << std::endl;
return !(el == r.el);
}