Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- using namespace std;
- class DynamicArray
- {
- int size;
- int* mas;
- public:
- DynamicArray()
- {
- size = 0;
- mas = nullptr;
- }
- DynamicArray(const DynamicArray& DynamicArray)
- {
- mas = new int[DynamicArray.size];
- for (int i = 0; i < DynamicArray.size; i++)
- mas[i] = DynamicArray.mas[i];
- size = DynamicArray.size;
- }
- ~DynamicArray()
- {
- size = 0;
- if (mas != nullptr)
- delete[] mas;
- }
- void display()
- {
- for (int i = 0; i < size; i++)
- cout << mas[i] << ' ';
- cout << endl;
- }
- void put(const int obi)
- {
- int sizesn = size + 1;
- int* massn = new int[sizesn];
- for (int i = 0; i < size; i++)
- massn[i] = mas[i];
- massn[size] = obi;
- if (mas != nullptr)
- delete[] mas;
- mas = massn;
- size = sizesn;
- }
- void retur(const int obj)
- {
- int sizesn = size - 1;
- int* massn = new int[sizesn];
- for (int i = 0; i < obj; i++)
- massn[i] = mas[i];
- for (int i = obj; i < sizesn; i++)
- massn[i] = mas[i + 1];
- if (mas != nullptr)
- delete[] mas;
- mas = massn;
- size = sizesn;
- }
- };
- void main()
- {
- DynamicArray Func;
- Func.put(222);
- Func.display();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement