Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void PushBack(const T& value) {
- T* result;
- if (Array == nullptr) {
- result = new T[1];
- Array = result;
- end_ = Array + 1;
- }
- else if (arSize == (*this).Capacity()) {
- size_t capacity = (*this).Capacity() * 2;
- T* result = new T[capacity];
- for (unsigned int i = 0; i < arSize; ++i)
- result[i] = Array[i];
- Array = result;
- end_ = Array + capacity;
- }
- Array[arSize++] = value;
- }
- private:
- T* Array;
- T* end_;
- unsigned int arSize = 0;
- `template <typename T>
- class SimpleVector {
- public:
- SimpleVector() {
- Array = nullptr;
- end_ = Array;
- }
- explicit SimpleVector(size_t size) : Array(new T[size]), end_(Array + size){
- arSize += size;
- }
- ~SimpleVector() {
- delete[] Array;
- }
- T& operator[](size_t index) {
- return Array[index];
- }
- T* begin() {
- return Array;
- }
- T* end() {
- return end_;
- }
- size_t Size() const {
- return arSize;
- }
- size_t Capacity() const {
- return end_ - Array;
- }
- void PushBack(const T& value) {
- T* result;
- if (Array == nullptr) {
- result = new T[1];
- Array = result;
- end_ = Array + 1;
- }
- else if (arSize == (*this).Capacity()) {
- size_t capacity = (*this).Capacity() * 2;
- T* result = new T[capacity];
- for (unsigned int i = 0; i < arSize; ++i)
- result[i] = Array[i];
- Array = result;
- end_ = Array + capacity;
- }
- Array[arSize++] = value;
- }
- private:
- T* Array;
- T* end_;
- unsigned int arSize = 0;
- };`
- void PushBack(const T& value) {
- T* result;
- if (Array == nullptr) {
- result = new T[1];
- else if (arSize == (*this).Capacity()) {
- size_t capacity = (*this).Capacity() * 2;
- T* result = new T[capacity];
Add Comment
Please, Sign In to add comment