-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterator.hpp
70 lines (55 loc) · 1.23 KB
/
iterator.hpp
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
#ifndef __ITERATOR_HPP__
#define __ITERATOR_HPP__
#include <stack>
#include "base.hpp"
/*
#include "../lab03/base.hpp"
#include "../lab04/container.hpp"
*/
class Base;
enum ChildIndicator { left, right, end };
class Iterator {
protected:
Base* self_ptr;
public:
Iterator(Base* ptr) {
this->self_ptr = ptr;
}
virtual void first() = 0;
virtual void next() = 0;
virtual bool is_done() = 0;
virtual Base* current() = 0;
};
class BinaryIterator : public Iterator {
protected:
ChildIndicator c;
public:
BinaryIterator(Base* ptr);
void first();
void next();
bool is_done();
Base* current();
};
class NullIterator : public Iterator {
public:
NullIterator(Base* ptr) : Iterator(ptr) {}
void first() {}
void next() {}
bool is_done() {
return true;
}
Base* current() {
return nullptr;
}
};
class PreorderIterator : public Iterator {
protected:
std::stack<Iterator*> iterators;
public:
PreorderIterator(Base* ptr);
void first();
void next();
bool is_done();
Base* current();
};
#endif