Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <iostream>
- # include <algorithm>
- using namespace std;
- class MyVector
- {
- private:
- size_t size;
- int * data;
- size_t capacity;
- public:
- MyVector()
- {
- size = capacity = 0;
- data = nullptr;
- cout << "c'tor 1" << endl;
- }
- MyVector(size_t _size,int velue=0)
- {
- size = _size;
- capacity = size + size / 2;
- data = new int[capacity];
- fill(data, data + capacity, velue);
- //cout << "c'tor 2" << endl;
- }
- bool operator == (const MyVector &other) const //Константный метод
- {
- if (size != other.size) return false;
- for (size_t i = 0; i < size; i++)
- {
- if ( data[i]!=other.data[i])
- {
- return false;
- }
- }
- return true;
- }
- MyVector& operator = (const MyVector & other)
- {
- if (this == &other) return *this;
- delete[] data;
- size = other.size;
- capacity = other.capacity;
- data = new int[capacity];
- copy(other.data, other.data + capacity, data);
- return * this;
- }
- bool operator != (const MyVector & other) const
- {
- return !(*this == other);
- }
- //MyVector()
- //{
- //}
- void print()const
- {
- for (size_t i = 0; i < size; i++)
- {
- cout << data[i] << ' ';
- }
- cout << endl;
- }
- MyVector(const MyVector &other)
- {
- this->size = other.size;
- this->capacity = other.capacity;
- this->data = new int[this->capacity];
- copy(other.data, other.data + capacity, this->data);
- }
- ~MyVector()
- {
- delete[] data;
- //cout << "d'tor" << endl;
- }
- void push_back(int valuve)
- {
- if (size < capacity)
- {
- data[size] = valuve;
- size++;
- }
- }
- };
- void vectorPrinter(MyVector v)
- {
- v.print();
- }
- void main()
- {
- MyVector v1(5,2 );
- MyVector v2(5, 3);
- //v1.push_back(1);
- v1.print();
- //vectorPrinter(v);
- //if (v1==v2)
- //{
- // cout << " WORKS \n";
- //}
- //else
- //{
- //cout << "dont WORKS \n";
- //}
- v1 = v2;
- v1.print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement