#pragma once #include class Set { public: std::vector array; explicit Set(const std::vector &vec) { for (auto & i : vec) { this->Add(i); } } Set() {} std::vector Data() { return this->array; } void Add(int64_t number) { bool present = false; for (int64_t i : this->array) { if (i == number) { present = true; break; } } if (!present) { this->array.push_back(number); } } void Remove(int64_t number) { for (unsigned int i = 0; i < this->array.size(); i++) { if (this->array[i] == number) { this->array.erase(this->array.begin() + i); break; } } } bool Contains(int64_t number) const { for (int64_t i : this->array) { if (i == number) { return true; } } return false; } Set Union(const Set& other) { for (int64_t i : other.array) { this->Add(i); } return *this; } Set Intersection(const Set& other) { for (int i = 0; i < this->array.size(); i++) { if (!other.Contains(this->array[i])) { this->Remove(this->array[i]); i--; } } return *this; } Set Difference(const Set& other) const { Set *difference = new Set(); for (int64_t i : this->array) { if (!other.Contains(i)) { difference->Add(i); } } return *difference; } Set SymmetricDifference(const Set& other) const { Set *simdiff = new Set(); for (int64_t i : this->array) { if (!other.Contains(i)) { simdiff->Add(i); } } for (int64_t i : other.array) { if (!this->Contains(i)) { simdiff->Add(i); } } return *simdiff; } };