Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- class Vector {
- public:
- Vector() {
- arr_ = new int[4];
- size_ = 0;
- capacity_ = 4;
- }
- Vector(const int capacity) {
- arr_ = new int[capacity];
- size_ = 0;
- capacity_ = capacity;
- }
- void push_back(const int value) {
- if (size_ == capacity_) {
- int* temp = new int[capacity_ * 2];
- for (int i = 0; i < size_; i++) {
- temp[i] = arr_[i];
- }
- delete[] arr_;
- arr_ = temp;
- capacity_ *= 2;
- }
- arr_[size_] = value;
- size_++;
- }
- void insert(const int index, const int value) {
- }
- void pop_back() {
- if (size_ > 0) {
- size_--;
- }
- }
- void print() {
- for (int i = 0; i < size_; i++) {
- cout << arr_[i] << " ";
- }
- cout << endl;
- }
- private:
- int* arr_; // хранилище
- int size_; // текущее количество элементов
- int capacity_; // емкость хранилища
- };
- int main() {
- setlocale(LC_ALL, "ru");
- Vector vec1;
- vec1.push_back(10);
- vec1.push_back(15);
- vec1.push_back(20);
- vec1.push_back(25);
- vec1.print();
- vec1.pop_back();
- vec1.print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement