Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

template class Array { public: using value_type = T; // Iterators are just pointers to objects of type T using iterator = value_type*; using const_iterator

template

class Array

{

public:

using value_type = T;

// Iterators are just pointers to objects of type T

using iterator = value_type*;

using const_iterator = const value_type*;

using reference = value_type&;

using const_reference = const value_type&;

using size_type = size_t;

using difference_type = ptrdiff_t;

void

push_back (const T& item)

{

insert(end(),item);

}

// Reserve capacity for "space" elements.

// "space" must be greater than capacity.

// If not, leave the capacity unchanged.

// "size" must remain unchanged.

void

reserve (size_t space)

{

if (space > capacity ())

{

T* array = new T[space];

copy (begin (), end (), array);

delete[] m_array;

m_array = array;

m_capacity = space;

}

}

// TODO!

// Change the size to be "newSize".

// If "newSize" is less than "size",

// erase the last elements.

// If "newSize" is more than "size",

// insert "value"-s at the end.

void

resize (size_t newSize, const T& value = T ())

{

}

// TODO!

// Insert "item" before "pos", and return iterator pointing to "item".

// If the capacity is insufficient, DOUBLE it.

// If the capacity is 0, increase it to 1.

// NOTE: If a reallocation occurs, "pos" will be invalidated!

iterator

insert (iterator pos, const T& item)

{

}

private:

// Stores the number of elements in the Array.

size_t m_size;

// Stores the capacity of the Array, which must be at least "m_size".

size_t m_capacity;

// Stores a pointer to the first element in the Array.

T* m_array;

};

Help with

void

resize (size_t newSize, const T& value = T ())

{

}

and

iterator

insert (iterator pos, const T& item)

{

}

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

Students also viewed these Databases questions