bogolyubskiyalexey

Untitled

Mar 2nd, 2021
719
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. template<T>
  2. class MyVector {
  3. private:
  4.     size_t size_ = 0;
  5.     T* ptr_ = nullptr;
  6.     size_t capacity_ = 0;
  7.  
  8. public:
  9.     MyVector() = default;
  10.     MyVector(const MyVector& other) {
  11.         size_ = other.size_;
  12.         capacity_ = other.size_;
  13.         ptr_ = new T[size_];
  14.         for (size_t i = 0; i < size_; ++i) {
  15.             ptr_[i] = other.ptr_[i];
  16.         }
  17.     }
  18.     size_t size() const {
  19.         return size_;
  20.     }
  21.     size_t capacity() const {
  22.         return capacity_;
  23.     }
  24.     T& front() {
  25.         return ptr_[0];
  26.     }
  27.     const T& front() const {
  28.         return ptr_[0];
  29.     }
  30.     T& back() {
  31.         return ptr_[size_ - 1];
  32.     }
  33.     const T& back() const {
  34.         return ptr_[size_ - 1];
  35.     }
  36.     void push_back(const T& new_elem) {
  37.         if (size_ + 1 <= capacity_) {
  38.             ptr_[size_++] = new_elem;
  39.         } else {
  40.             capacity_ *= 2;
  41.             T* new_ptr_ = new T[capacity_];
  42.             for (size_t i = 0; i < size_; ++i) {
  43.                 new_ptr_[i] = ptr_[i];
  44.             }
  45.             delete[] ptr_;
  46.             ptr_ = new_ptr_;
  47.             ptr[size_++] = new_elem;
  48.         }
  49.     }
  50. }
  51.  
  52.  
  53.  
  54.     - MyVector()
  55.     - MyVector(const MyVector&)
  56.     - size
  57.     - capacity
  58.     - front
  59.     - back
  60.     - push_back(value)
  61.     += myvector
  62.     a+b
  63.    
  64.     int* a = new int;
  65.     *a = 12334;
  66.     delete a;
  67.    
  68.     int* b = new int[100];
  69.     b[10] = 100;
  70.     b[2] = 2;
  71.     *b <=> b[0]
  72.    
  73.    
  74.     delete[] b;
  75.    
  76.    
  77.    
  78.    
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×