Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Structures and data algorithms / Project / exc / Box.cpp
diff options
context:
space:
mode:
Commit77df09397e7fc517dd387d8e46d993ad30f69853 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-12-29 10:12:20 +0200
Committer
 Syndamia <kamen@syndamia.com>
2022-12-29 10:12:20 +0200
Filesb38c4fcd01f748f780f03f34bc51730ddf728ade /Year 2/Structures and data algorithms/Project/exc/Box.cpp
uni-projects-77df09397e7fc517dd387d8e46d993ad30f69853.tar
uni-projects-77df09397e7fc517dd387d8e46d993ad30f69853.tar.gz
uni-projects-77df09397e7fc517dd387d8e46d993ad30f69853.zip
Parentb6e654657da058e9a438ec4583fac8028758dfb4 (diff)
[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.cpp27
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)