Практика 8
#include "vector.h" | |
vector_int::vector_int() { | |
size_ = 0; | |
capacity_ = 16; | |
data_ = new int[capacity_]; | |
} | |
void vector_int::reserve(size_t new_size) { | |
if (new_size <= capacity_) | |
return; | |
capacity_ = new_size; | |
int *new_data = new int[capacity_]; | |
for (size_t i = 0; i != size_; i++) { | |
new_data[i] = data_[i]; | |
} | |
delete[] data_; | |
data_ = new_data; | |
} |
#pragma once | |
#include <cstddef> | |
class vector_int { | |
public: | |
vector_int(); | |
~vector_int(); | |
vector_int(const vector_int& other); | |
vector_int& operator=(const vector_int& other); | |
void push_back(int x); | |
void reserve(size_t new_size); | |
int& operator[](size_t id); | |
const int& operator[](size_t id) const; | |
private: | |
int *data_; | |
size_t size_; | |
size_t capacity_; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment