Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
diff --git a/Year 2/Structures and data algorithms/Project/exc/Box.cpp b/Year 2/Structures and data algorithms/Project/exc/Box.cpp
new file mode 100644
index 0000000..844a337
--- /dev/null
+++ b/Year 2/Structures and data algorithms/Project/exc/Box.cpp
@@ -0,0 +1,31 @@
+#include "Box.h"
+
+void Box::removeUselessSubBoxes() {
+ for (auto i = subboxes.begin(); i != subboxes.end(); ++i) {
+ if ((*i)->items.empty() && (*i)->subboxes.size() < 2) {
+ if ((*i)->subboxes.empty()) {
+ 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;
+
+ indent += " ";
+ for (Box* sb : subboxes)
+ sb->printWithInd(ostr, indent);
+ return ostr;
+}
+
+std::ostream& Box::print(std::ostream& ostr) {
+ return printWithInd(ostr, "");
+}
diff --git a/Year 2/Structures and data algorithms/Project/exc/Box.h b/Year 2/Structures and data algorithms/Project/exc/Box.h
new file mode 100644
index 0000000..2a0c71b
--- /dev/null
+++ b/Year 2/Structures and data algorithms/Project/exc/Box.h
@@ -0,0 +1,23 @@
+#ifndef BOX
+#define BOX
+
+#include <string>
+#include <vector>
+#include <ostream>
+#include <istream>
+
+class Box {
+ std::string name;
+ std::vector<std::string> items;
+ std::vector<Box*> subboxes;
+
+ std::ostream& printWithInd(std::ostream&, std::string);
+
+public:
+ Box(const std::string& name, const std::vector<std::string>& items, const std::vector<Box*> subboxes) : name(name), items(items), subboxes(subboxes) {}
+
+ void removeUselessSubBoxes();
+ std::ostream& print(std::ostream&);
+};
+
+#endif
diff --git a/Year 2/Structures and data algorithms/Project/exc/main.cpp b/Year 2/Structures and data algorithms/Project/exc/main.cpp
new file mode 100644
index 0000000..e9d7032
--- /dev/null
+++ b/Year 2/Structures and data algorithms/Project/exc/main.cpp
@@ -0,0 +1,9 @@
+#include "Box.h"
+#include <iostream>
+
+int main() {
+ Box plovdivBox("PlovdivBox", { "Magnet", "Book" }, { new Box("ArtBox", {}, { new Box("Drawings", { "OldPlovdiv" }, {}) }), new Box("TheatreBox", {}, { new Box("TheatreSouvenirs", {}, { new Box("Plates", { "DecorativePlate" }, {}), new Box("Bags", {}, {}) }) })});
+ plovdivBox.print(std::cout) << std::endl;
+ plovdivBox.removeUselessSubBoxes();
+ plovdivBox.print(std::cout) << std::endl;
+}