#include #include #include class Set { public: Set(); explicit Set(const std::vector &elements) : elements(elements) { } void Add(int64_t new_element) { if (!this->Contains(new_element)) { elements.push_back(new_element); std::sort(elements.begin(), elements.end()); } } void Remove(int64_t old_element) { auto it = std::find(elements.begin(), elements.end(), old_element); elements.erase(it); } bool Contains(int64_t element) const { for (const auto &item: elements) { if (item == element) { return true; } } return false; } Set Union(const Set &second_set) const { std::vector new_set = elements; for (const auto &item: second_set.Data()) { if (!this->Contains(item)) { new_set.push_back(item); } } std::sort(new_set.begin(), new_set.end()); return new_set; } Set Intersection(const Set &second_set) const { Set new_set; for (auto &item: elements) { if (second_set.Contains(item)) { new_set.Add(item); } } return new_set; } Set Difference(const Set &second_set) const { Set new_set; for (auto &item: elements) { if (!second_set.Contains(item)) { new_set.Add(item); } } return new_set; } Set SymmetricDifference(const Set &second_set) const { Set new_set; Set A; Set B; A = this->Difference(second_set); B = second_set.Difference(*this); new_set = A.Union(B); return new_set; } std::vector Data() const { return elements; } private: std::vector elements; };