Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with my code. Im not sure what to write anymore. C++ #include #include #include template class MyVector { public: static constexpr size_t

Please help me with my code. Im not sure what to write anymore. C++

#include

#include

#include

template

class MyVector {

public:

static constexpr size_t DEFAULT_CAPACITY = 64;

static constexpr size_t MINIMUM_CAPACITY = 8;

MyVector(size_t capacity = MyVector::DEFAULT_CAPACITY) {

// TODO: Your code here

capacity_ = capacity;

size_ = 0;

}

MyVector(const MyVector &other) {

capacity_ = other.capacity_;

size_ = other.size_;

data_ = new T[capacity_];

data_[i] = other.data_[i];

}

~MyVector() {

delete[] data_;

}

MyVector &operator=(const MyVector &rhs) {

capacity_ = rhs.capacity_;

size_ = rhs.size_;

data_ = new T[capacity_];

data_[i] = rhs.data_[i];

return *this;

}

}

T &

operator[](size_t index) const {

assert(index < size_);

return data_[index];

}

size_t size() const {

return size_;

}

/// Return the capacity of our internal array

size_t capacity() const {

return capacity_;

}

// check if vector is empty return true if empty, return false otherwise

bool empty() const {

if (size_t(size_) == 0) {

return true;

}

return false;

}

/// Return a reference to the element at an index

T &at(size_t index) const {

}

void reserve(size_t capacity) {

}

T &set(size_t index, const T &element) {

}

/**

* Add element onto end of vector, increasing size by 1

* Should rely on insert() function . Return reference to the newly inserted element

*/

T &push_back(const T &element) {

}

size_t pop_back() {

}

/**

* Insert an element at some index in our vector, increasing the size by 1

* push elements at index , one to the right. This

* then place

* the new element.

* Returns a reference to the newly added element

*/

T &insert(size_t index, const T &element) {

}

/**

* Erase one element in our vector at the specified index, decreasing the size by 1.

*push elements to the left to fill the "hole"

*left by the erased element.

*Throws std::range_error if the index is out of bounds.

*Call erased element's destructor.

*Return new size.

*/

size_t erase(size_t index) {

}

void clear() {

}

private:

size_t size_ = 0;

size_t capacity_ = 0;

T *elements_ = nullptr;

void changeCapacity(size_t c) {

}

void copyOther(const MyVector &other){

};

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

What do we mean by closed-canopy forest and old-growth forest?

Answered: 1 week ago