#pragma once #include #include #include "iterators/BaseIterator.h" template class DFSIterator : public BaseIterator { public: explicit DFSIterator(T* ptr) : BaseIterator(ptr), level_(0) { if (!this->current) return; for (auto it = BaseIterator::current->children().rbegin(); it != BaseIterator::current->children().rend(); ++it) s.push({it->get(), 1}); } IIterator& operator++() override { advance(); return *this; } virtual size_t level() const { return level_; } protected: std::stack> s; size_t level_; void advance() { if (s.empty()) { this->current = nullptr; return; } auto [node, lvl] = s.top(); s.pop(); this->current = node; level_ = lvl; for (auto it = this->current->children().rbegin(); it != this->current->children().rend(); ++it) s.push({it->get(), lvl + 1}); } };