| 36 | |
| 37 | public: |
| 38 | class iterator |
| 39 | { |
| 40 | public: |
| 41 | iterator() : ptr_(nullptr) {} |
| 42 | iterator(node *ptr) : ptr_(ptr) {} |
| 43 | iterator(const iterator &it) { ptr_ = it.ptr_; } |
| 44 | iterator &operator=(iterator it) |
| 45 | { |
| 46 | if (this == &it) |
| 47 | return *this; |
| 48 | ptr_ = it.ptr_; |
| 49 | return *this; |
| 50 | } |
| 51 | |
| 52 | iterator &operator--() |
| 53 | { |
| 54 | node *prev = ptr_; |
| 55 | if (ptr_ != nullptr) |
| 56 | { |
| 57 | if (ptr_->left != nullptr) |
| 58 | { |
| 59 | ptr_ = ptr_->left.get(); |
| 60 | while (ptr_->right != nullptr) |
| 61 | { |
| 62 | ptr_ = ptr_->right.get(); |
| 63 | } |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | ptr_ = ptr_->parent; |
| 68 | while (ptr_ != nullptr && ptr_->left.get() == prev) |
| 69 | { |
| 70 | prev = ptr_; |
| 71 | ptr_ = ptr_->parent; |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | return *this; |
| 76 | } |
| 77 | iterator &operator++() |
| 78 | { |
| 79 | node *prev = ptr_; |
| 80 | if (ptr_ != nullptr) |
| 81 | { |
| 82 | if (ptr_->right != nullptr) |
| 83 | { |
| 84 | ptr_ = ptr_->right.get(); |
| 85 | while (ptr_->left) |
| 86 | ptr_ = (ptr_->left).get(); |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | ptr_ = ptr_->parent; |
| 91 | while (ptr_ != nullptr && ptr_->right.get() == prev) |
| 92 | { |
| 93 | prev = ptr_; |
| 94 | ptr_ = ptr_->parent; |
| 95 | } |