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;
- }
- void print()
- {
- for (size_t i = 0; i < size; i++)
- {
- cout << data[i] << ' ';
- }
- }
- 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 v(5,2 );
- v.push_back(1);
- v.print();
- //vectorPrinter(v);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement