Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "Set.h"
- template<typename T>
- Set<T>::Set () : ammount (sizeblock)
- {
- this->mas = 0;
- this->capasity = 0;
- }
- template<typename T>
- Set<T>::Set (int count, ...) : ammount (sizeblock)
- {
- int n = count / this->ammount + (1 - !(count%this->ammount));
- this->capacity = count;
- this->mas = new T[n*this->ammount];
- T* p = (T*)(&count + 1);
- for (int i = 0; i < this->capacity; i++)
- this->mas[i] = p[i];
- }
- template<typename T>
- Set<T>::Set (const Set<T>& s) : ammount (sizeblock)
- {
- int n = s.capacity / s.ammount + (1 - !(s.capacity%s.ammount));
- this->capacity = s.capacity;
- this->mas = new T[n*this->ammount];
- for (int i = 0; i < this->capacity; i++)
- this->mas[i] = s.mas[i];
- }
- template<typename T>
- Set<T>::Set (Set<T>&& s) : ammount (sizeblock)
- {
- this->capacity = s.capacity;
- this->mas = s.mas;
- s.mas = 0;
- }
- template<typename T>
- Set<T>::~Set ()
- {
- delete mas;
- }
- template<typename T>
- Set<T>& Set<T>::operator=(const Set<T>& s)
- {
- this->capacity = s.capacity;
- int n = s.capacity / s.ammount + (1 - !(s.capacity%s.ammount));
- delete this->mas;
- this->mas = new T[n*this->ammount];
- for (int i; i < this->capacity; i++)
- this->mas[i] = s.mas[i];
- }
- template<typename T>
- Set<T>& Set<T>::operator=(Set<T>&& s)
- {
- this->capacity = s.capacity;
- this->mas = s.mas;
- s.mas = 0;
- }
- template<typename T>
- inline void Set<T>::sortSet (int left, int right) const
- {
- }
- //_________________________________________________//
- template <typename T>
- bool Set<T>::empty() const
- {
- if (this->mas == NULL)
- return false;
- else
- return true;
- }
- template <typename T>
- bool Set<T>::belong (const T& elem) const
- {
- bool res = false;
- for (int i = 0; i < this->capacity; i++)
- if (this->mas[i] == elem)
- {
- res = true;
- break;
- }
- return res;
- }
- template <typename T>
- bool Set<T>::add(const T& elem)
- {
- if (/*!(this->empty () ||*/ this->belong (elem)))
- return false;
- else
- {
- int n = (this->capacity + 1) / this->ammount + (1 - !((this->capacity + 1)%this->ammount));
- if (n*this->ammount > this->ammount)
- {
- this->ammount = n*this->ammount;
- this->capacity++;
- this->mas = (T*)realloc (this->mas, (this->ammount) * sizeof (T));
- this->mas[(this->capacity - 1)] = el;
- }
- else
- this->mas[this->capacity++] = el;
- return true;
- }
- }
- template <typename T>
- bool Set<T>::operator <(const T& elem) const
- {
- return this->belong (elem);
- }
- template <typename T>
- void Set<T>::sortSet (int left, int right) const
- {
- int i = left;
- int j = right;
- T tmp = this->mas[(left + right) / 2];
- T tmpSwap;
- while (i <= j)
- {
- while (this->mas[i] < tmp)
- i++;
- while (this->mas[j] > tmp)
- j--;
- if (j <= j)
- {
- tmpSwap = this - < mas[i];
- this->mas[i] = this->mas[j];
- this->mas[j] = tmpSwap;
- i++;
- j--:
- }
- };
- if (left < j) sortSet (left, j);
- if (i < right) sortSet (i, right);
- }
- template <typename T>
- Set<T> Set<T>::operator +(const Set<T>& s) const
- {
- this->sortSet (0, this->capacity - 1);
- s.sortSet (0, s.capacity - 1);
- Set<T> res;
- int i = 0, j = 0;
- while (i < this->capacity && j < s.capacity)
- {
- if (this->mas[i] == s.mas[j])
- {
- res.add (this->mas[j]);
- i++;
- }
- else
- {
- if (this->mas[i] < s.mas[j])
- {
- res.add (this->mas[i]);
- i++;
- }
- else
- {
- res.add (s.mas[j]);
- j++;
- }
- }
- }
- while (i < this->capacity)
- {
- res.add (this->mas[i]) :
- i++;
- }
- while (j < s.capacity)
- {
- res.add (s.mas[j]);
- j++;
- }
- return res;
- }
- template <typename T>
- bool Set<T>::del (const T& elem)
- {
- if (!this->belong (elem))
- return false;
- else
- {
- int tmp;
- for (tmp = 0; tmp < this->capacity; i++)
- if (elem == this->mas[tmp])
- break;
- for (int i = tmp; i < this->capacity - 1; i++)
- this->mas[i] = this->mas[i + 1];
- this->mas = (T*)realloc (this->mas, (this->capacity - 1)*sizeof (T));
- this->capacity--;
- int n = this->capacity / this->ammount + (1 - !(this->capacity % this->ammount));
- this->mas = (T*)realloc (this->mas, n*this->ammount*sizeof (T));
- return true;
- }
- }
- template <typename T>
- Set<T> Set<T>::operator +(const T& elem) const
- {
- Set res;
- res.add (res);
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement