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