From 0e9be940d16311036ee36aed47406481a26fdd82 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 27 Dec 2022 12:36:09 +0200 Subject: [SDP/P] Only direct subboxes are removed in third exercise --- .../Project/exc/Box.cpp | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Year 2/Structures and data algorithms/Project/exc/Box.cpp (limited to 'Year 2/Structures and data algorithms/Project/exc/Box.cpp') 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, ""); +} -- cgit v1.3.1-23-gd82d