#include #include class Set { private: const int FLAGS = 10e9; public: std::vector set; Set() { } Set& operator=(const Set& other) { this->set = other.set; return *this; } explicit Set(const std::vector& vec) { std::vector flags(FLAGS, false); for (int i = 0; i < vec.size(); i++) { if (!flags[vec[i]]) { flags[vec[i]] = true; this->set.push_back(vec[i]); } } sort(this->set.begin(), this->set.end()); } Set Union(const Set& join_set) { std::vector flags(FLAGS, false); std::vector new_set; for (int i = 0; i < join_set.set.size(); i++) { if (!flags[join_set.set[i]]) { new_set.push_back(join_set.set[i]); flags[join_set.set[i]] = true; } } for (int i = 0; i < this->set.size(); i++) { if (!flags[this->set[i]]) { new_set.push_back(this->set[i]); flags[this->set[i]] = true; } } sort(new_set.begin(), new_set.end()); return { new_set }; } Set Intersection(const Set& s) { std::vector result; for (int i = 0; i < join_set.set.size(); i++) { if (std::find(this->set.begin(), this->set.end(), s.set[i]) != this->set.end()) { result.push_back(s.set[i]); } } return { result }; } Set Difference(const Set& join_set) { std::vector result; for (int i = 0; i < join_set.set.size(); i++) { if (std::find(this->set.begin(), this->set.end(), join_set.set[i]) == this->set.end()) { result.push_back(join_set.set[i]); } } return { result }; } Set SymmetricDifference(const Set& join_set) { std::vector result; for (int i = 0; i < join_set.set.size(); i++) { if (std::find(this->set.begin(), this->set.end(), join_set.set[i]) == this->set.end()) { result.push_back(join_set.set[i]); } } for (int i = 0; i < this->set.size(); i++) { if (std::find(join_set.set.begin(), join_set.set.end(), this->set[i]) == join_set.set.end()) { result.push_back(this->set[i]); } } return { result }; } void Add(int64_t element) { if (std::find(this->set.begin(), this->set.end(), element) == this->set.end()) { this->set.push_back(element); } } bool Contains(int64_t element) { for (int i = 0; i < this->set.size(); i++) { if (this->set[i] == element) { return true; } } return false; } void Remove(int64_t element) { for (int i = 0; i < this->set.size(); i++) { if (this->set[i] == element) { this->set.erase(this->set.begin() + i); } } } std::vector Data() { return this->set; } void Print() { for (auto temp : set) { std::cout << temp << " "; } std::cout << std::endl; } };