diff options
[SDP/P/exc] Added file reading
1 files changed, 21 insertions, 6 deletions
| -rw-r--r-- | Year 2/Structures and data algorithms/Project/exc/Box.cpp | 27 |
diff --git a/Year 2/Structures and data algorithms/Project/exc/Box.cpp b/Year 2/Structures and data algorithms/Project/exc/Box.cpp index 844a337..85f65ff 100644 --- a/Year 2/Structures and data algorithms/Project/exc/Box.cpp +++ b/Year 2/Structures and data algorithms/Project/exc/Box.cpp @@ -1,24 +1,39 @@ #include "Box.h" +Box::Box(const std::string& name) : name(name), items(), subboxes() +{} +Box::Box(const std::string& name, const std::deque<std::string>& items, const std::deque<Box*> subboxes) : name(name), items(items), subboxes(subboxes) +{} + +std::string& Box::get_name() { + return name; +} + +void Box::pushItem(std::string item) { + items.push_back(item); +} + +void Box::pushSubbox(Box* subbox) { + subboxes.push_back(subbox); +} + void Box::removeUselessSubBoxes() { - for (auto i = subboxes.begin(); i != subboxes.end(); ++i) { + for (auto i = subboxes.begin(), end = subboxes.end(); i != end; ++i) { + (*i)->removeUselessSubBoxes(); if ((*i)->items.empty() && (*i)->subboxes.size() < 2) { if ((*i)->subboxes.empty()) { - subboxes.erase(i); + subboxes.erase(i); // затова държа самия итератор continue; } - *i = (*i)->subboxes[0]; } - // else - // (*i)->removeUselessSubBoxes(); } } std::ostream& Box::printWithInd(std::ostream& ostr, std::string indent) { ostr << indent << name << std::endl; for (std::string& i : items) - ostr << indent << "+ " << i << std::endl; + ostr << indent << " + " << i << std::endl; indent += " "; for (Box* sb : subboxes) |
