#ifndef SET_SET_H #define SET_SET_H #pragma once #include #include #include class Set { private: std::vector set; public: explicit Set(const std::vector&s = {}) { for (int64_t k : s) { if (std::find(set.begin(), set.end(), k) == set.end()) { set.push_back(k); sort(set.begin(), set.end()); } } } std::vector Data() const { return set; } Set Union(const Set&) const; Set Intersection(const Set&) const; Set Difference(const Set&) const; Set SymmetricDifference(const Set&) const; void Add(int64_t); void Remove(int64_t); bool Contains(int64_t) const; }; Set Set::Union(const Set &other) const { Set NewSet; for (auto i : set) NewSet.Add(i); for (auto i : other.set) NewSet.Add(i); return NewSet; } Set Set::Intersection(const Set &other) const { Set NewSet; for (auto i : set) { if (std::find(other.set.begin(), other.set.end(), i) != other.set.end()) NewSet.Add(i); } return NewSet; } Set Set::Difference(const Set& s) const { Set NewSet; for (int64_t k : set) { if (!(std::find(s.set.begin(), s.set.end(), k) != s.set.end())) { NewSet.Add(k); } } return NewSet; } Set Set::SymmetricDifference(const Set& s) const { Set NewSet; for (int64_t k : s.set) { if (!(std::find(set.begin(), set.end(), k) != set.end())) { NewSet.Add(k); } } for (int64_t k : set) { if (!(std::find(s.set.begin(), s.set.end(), k) != s.set.end())) { NewSet.Add(k); } } return NewSet; } void Set::Add(int64_t num) { if (std::find(set.begin(), set.end(), num) == set.end()) { set.push_back(num); sort(set.begin(), set.end()); } } void Set::Remove(int64_t num) { auto it = std::find(set.begin(), set.end(), num); if (it != set.end()) set.erase(it); } bool Set::Contains(int64_t num) const { return std::find(set.begin(), set.end(), num) != set.end(); } #endif