Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Set::Set()
- {
- for (int i = 0; i < size; i++)
- {
- data[i] = 0;
- }
- }
- size_t Set::getPosition(char symbol)
- {
- size_t position;
- position = (symbol - 'a') % (sizeof(char)*8) ;
- return position ;
- }
- size_t Set::getArrayIndex(char symbol)
- {
- size_t arrIndex;
- arrIndex = (symbol - 'a') / (sizeof(char) * 8) ;
- return arrIndex ;
- }
- bool Set::isInSet(char symbol)
- {
- size_t index;
- index = getArrayIndex(symbol);
- size_t position;
- position = getPosition(symbol);
- bool result;
- result = false;
- if (data[index] & (0x1 << position))
- {
- result = true;
- }
- return result;
- }
- void Set::add(char symbol)
- {
- size_t index;
- index = getArrayIndex(symbol);
- size_t position;
- position = getPosition(symbol);
- data[index] |= 0x1 << position;
- }
- void Set::remove(char symbol)
- {
- size_t index;
- index = getArrayIndex(symbol);
- size_t position;
- position = getPosition(symbol);
- if (!(data[index] & (0x1 << position)))
- {
- throw "this element does not exits at this set \n";
- }
- data[index] &= ~(0x1 << position);
- }
- bool Set::isEmpty()
- {
- for (size_t i = 0; i < this->size; i++)
- {
- if (data[i] != 0)
- {
- return false;
- }
- }
- return true;
- }
- Set Set::combineSets(const Set& set)
- {
- Set newSet;
- for (size_t i = 0; i < size; i++)
- {
- newSet.data[i] = this->data[i] | set.data[i];
- }
- return newSet;
- }
- Set Set::intersectionOfSets(const Set& set)
- {
- Set newSet;
- for (size_t i = 0; i < size; i++)
- {
- newSet.data[i] = this->data[i] & set.data[i];
- }
- return newSet;
- }
- Set Set::subtractionOfSets(const Set& set)
- {
- Set newSet;
- newSet = (*this);
- for (size_t i = 0; i < size; i++)
- {
- newSet.data[i] &= ~set.data[i];
- }
- return newSet;
- }
- char Set::getMinElement()
- {
- int index;
- index = -1;
- int partOfSet;
- partOfSet = 0;
- bool isFound;
- isFound = false;
- for (size_t i = 0; i < size; i++)
- {
- size_t pos = 0;
- while (pos < 8)
- {
- if (data[i] & (0x1 << pos))
- {
- index = pos;
- partOfSet = i;
- isFound = true;
- break;
- }
- pos++;
- }
- if (isFound)
- {
- break;
- }
- }
- if (index == -1)
- {
- throw "min element not found ";
- }
- return char (index+ 8*partOfSet +'a');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement