Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using std::copy; using std::copy_backward; using std::distance; using std::fill; using std::ostream; using std::ptrdiff_t; template class Array { public: using value_type = T; // Iterators are just

using std::copy;

using std::copy_backward;

using std::distance;

using std::fill;

using std::ostream;

using std::ptrdiff_t;

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

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions

Question

What is the purpose of a competitor analysis?

Answered: 1 week ago