Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class IntSet(){
- IntSet::IntSet(std::size_t max_elem)
- {
- :_nm(0)
- , _cp(max_elem)
- , _data((int *)malloc(_cp * sizeof(int)))
- assert(_data)
- }
- IntSet::~IntSet()
- {
- free(this->data)
- }
- IntSet::IntSet(const IntSet &other)
- {
- _nm = other._nm; //:_nm(other._nm)
- _cp = other._cp; //,_cp(other._cp)
- _data = (int *)std::malloc(_cp * sizeof(int));
- assert(_data);
- std::memcpy(_data, other._data, sizeof(int) * _nm);
- }
- IntSet::swap(IntSet &other)
- {
- using std::swap; //automatically destruct of copy (other), so free is not needed
- swap(_nm, _cp);
- }
- &IntSet IntSet::operator=(IntSet other)
- {
- swap(other);
- return *this;
- }
- //want to realize "<<" as adding operator
- &IntSet IntSet::operator<<(int elem)
- {
- assert(nm < _cp);
- _nm++;
- *(data + sizeof(int)) = elem;
- return *this;
- }
- //want to check if the element with value elem is in array
- bool IntSet::operator[](int elem)
- {
- for (std::size_t i = 0; i < _nm; i++)
- {
- if (_data[i] == elem)
- {
- return true;
- }
- }
- return false;
- }
- //want to check if A belongs to B
- bool IntSet::operator<=(const IntSet &other)
- {
- for (std::size_t i = 0; i < _nm; i++)
- {
- if (! other[_data[i]])
- {
- return false;
- }
- }
- return true;
- }
- //want to check if arrays are the same
- bool IntSet::operator==(const IntSet &other)
- {
- return *this<=other && other<=*this;
- }
- //want to
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement