SlideShare a Scribd company logo
1 of 13
Download to read offline
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <iterator>
/************************************************************/
// Local includes
/************************************************************/
// Using declarations
// YOU DO NOT NECESSARILY NEED TO USE ALL OF THESE!
using std::copy;
using std::copy_backward;
using std::distance;
using std::fill;
using std::ostream;
using std::ptrdiff_t;
/************************************************************/
template<typename T>
class Array
{
public:
//*****************************************************
// DO NOT MODIFY THIS SECTION!
// Some standard Container type aliases
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;
//*****************************************************
// Default ctor.
// Initialize an empty Array.
// This method is complete, and does NOT need modification.
// Remember to use a _member initialization list_ for each ctor,
// like I have below for the default ctor.
Array ()
: m_size (0),
m_capacity (0),
m_array (nullptr)
{
}
// Size ctor.
// Initialize an Array of size "pSize", with each element
// set to "value".
explicit Array (size_t pSize, const T& value = T ())
: m_size (pSize),
m_capacity (pSize),
m_array (new T[m_capacity])
{
fill (begin (), end (), value);
}
// TODO!
// Range ctor.
// Initialize an Array from the range [first, last).
// "first" and "last" must be Array iterators or pointers
// into a primitive array.
Array (const_iterator first, const_iterator last)
:m_size(distance(first,last)),m_capacity(m_size),m_array(new T[m_capacity])
{
copy(first,last,m_array);
}
// TODO!
// Copy ctor.
// Initialize this object from "a".
Array (const Array& a)
:m_size(a.m_size),m_capacity(a.m_capacity),m_array(new T[m_capacity])
{
copy(a.begin(),a.end(),m_array);
}
// TODO!
// Destructor.
// Release allocated memory.
~Array ()
{
delete[] m_array;
}
// TODO!
// Assignment operator.
// Assign "a" to this object.
// Be careful to check for self-assignment.
Array&
operator= (const Array& a)
{
if (this != &a)
{
delete[] m_array;
m_size = a.m_size;
m_capacity = a.m_capacity;
m_array = new T[m_capacity];
copy(a.begin(),a.end(),m_array);
}
return *this;
}
// Return the size.
size_t
size () const
{
return m_size;
}
// TODO!
// Return true if this Array is empty, false o/w.
bool
empty () const
{
return m_size == 0;
}
// TODO!
// Return the capacity.
size_t
capacity () const
{
return m_capacity;
}
// TODO!
// Return the element at position "index".
T& operator[] (size_t index)
{
return m_array[index];
}
// TODO!
const T& operator[] (size_t index) const
{
return m_array[index];
}
// TODO!
// Insert an element at the back.
// If the capacity is insufficient, DOUBLE it.
// If the capacity is 0, increase it to 1.
void
push_back (const T& item)
{
if (m_size == 0)
{
m_capacity = 1;
m_array = new T[m_capacity];
}
else if (m_size == m_capacity)
{
m_capacity *= 2;
T* temp = new T[2 * m_capacity];
copy(begin(),end(),temp);
delete[] m_array;
m_array = temp;
}
m_array[m_size] = item;
++m_size;
}
// TODO!
// Erase the element at the back.
void
pop_back ()
{
if (m_size > 0)
{
--m_size;
}
}
// 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 ())
{
if (newSize == m_size)
{
return;
}
if (newSize < m_size)
{
m_size = newSize;
return;
}
if (newSize > m_capacity)
{
reserve(newSize);
}
fill (begin (), end (), value);
m_size = newSize;
}
// 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)
{
}
// TODO!
// Remove element at "pos", and return an iterator
// referencing the next element.
iterator
erase (iterator pos)
{
copy(pos + 1, end(), pos);
-- m_size;
return pos;
}
// TODO!
// Return iterator pointing to the first element.
iterator
begin ()
{
return m_array;
}
// TODO!
const_iterator
begin () const
{
return m_array;
}
// TODO!
// Return iterator pointing one beyond the last element.
iterator
end ()
{
return m_array + m_size;
}
// TODO!
const_iterator
end () const
{
return m_array + m_size;
}
// Return a pointer to the underlying dynamic array
T*
data ()
{
return m_array;
}
// Return a pointer to the underlying dynamic array
T const*
data () const
{
return m_array;
}
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;
};
Fix the below error with the member function resize:
Help with
iterator
insert (iterator pos, const T& item)
{
}
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf

More Related Content

Similar to #include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf

@author Derek Harter @cwid 123 45 678 @class .docx
@author Derek Harter  @cwid   123 45 678  @class  .docx@author Derek Harter  @cwid   123 45 678  @class  .docx
@author Derek Harter @cwid 123 45 678 @class .docxadkinspaige22
ย 
template-typename T- class Array { public- using value_type - T- -- It (1).pdf
template-typename T- class Array { public- using value_type - T- -- It (1).pdftemplate-typename T- class Array { public- using value_type - T- -- It (1).pdf
template-typename T- class Array { public- using value_type - T- -- It (1).pdfashokadyes
ย 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdffsenterprises
ย 
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfNeed Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfEdwardw5nSlaterl
ย 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdfafgt2012
ย 
Use a simple vector you created before to create two other more
Use a simple vector you created before to create two other more Use a simple vector you created before to create two other more
Use a simple vector you created before to create two other more steviesellars
ย 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfaksahnan
ย 
Fix my codeCode.pdf
Fix my codeCode.pdfFix my codeCode.pdf
Fix my codeCode.pdfConint29
ย 
include ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfinclude ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfnaslin841216
ย 
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
Java Foundations StackADT-java ---  - Defines the interface to a stack.docxJava Foundations StackADT-java ---  - Defines the interface to a stack.docx
Java Foundations StackADT-java --- - Defines the interface to a stack.docxVictorXUQGloverl
ย 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfsales98
ย 
include ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfinclude ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfaathmiboutique
ย 
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxAvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxrock73
ย 
Please complete ALL of the ๏ฟฝTO DO๏ฟฝs in this code. I am really strugg.pdf
Please complete ALL of the ๏ฟฝTO DO๏ฟฝs in this code. I am really strugg.pdfPlease complete ALL of the ๏ฟฝTO DO๏ฟฝs in this code. I am really strugg.pdf
Please complete ALL of the ๏ฟฝTO DO๏ฟฝs in this code. I am really strugg.pdfsupport58
ย 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfARCHANASTOREKOTA
ย 
Character.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdfCharacter.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdftxkev
ย 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxssuser454af01
ย 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfcontact41
ย 

Similar to #include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf (20)

@author Derek Harter @cwid 123 45 678 @class .docx
@author Derek Harter  @cwid   123 45 678  @class  .docx@author Derek Harter  @cwid   123 45 678  @class  .docx
@author Derek Harter @cwid 123 45 678 @class .docx
ย 
template-typename T- class Array { public- using value_type - T- -- It (1).pdf
template-typename T- class Array { public- using value_type - T- -- It (1).pdftemplate-typename T- class Array { public- using value_type - T- -- It (1).pdf
template-typename T- class Array { public- using value_type - T- -- It (1).pdf
ย 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdf
ย 
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfNeed Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
ย 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
ย 
Use a simple vector you created before to create two other more
Use a simple vector you created before to create two other more Use a simple vector you created before to create two other more
Use a simple vector you created before to create two other more
ย 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
ย 
Fix my codeCode.pdf
Fix my codeCode.pdfFix my codeCode.pdf
Fix my codeCode.pdf
ย 
include ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfinclude ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdf
ย 
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
Java Foundations StackADT-java ---  - Defines the interface to a stack.docxJava Foundations StackADT-java ---  - Defines the interface to a stack.docx
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
ย 
Js hacks
Js hacksJs hacks
Js hacks
ย 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdf
ย 
include ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfinclude ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdf
ย 
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docxAvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
AvlTree.h#ifndef AVL_TREE_H#define AVL_TREE_H#include d.docx
ย 
Please complete ALL of the ๏ฟฝTO DO๏ฟฝs in this code. I am really strugg.pdf
Please complete ALL of the ๏ฟฝTO DO๏ฟฝs in this code. I am really strugg.pdfPlease complete ALL of the ๏ฟฝTO DO๏ฟฝs in this code. I am really strugg.pdf
Please complete ALL of the ๏ฟฝTO DO๏ฟฝs in this code. I am really strugg.pdf
ย 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
ย 
Character.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdfCharacter.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdf
ย 
Link list
Link listLink list
Link list
ย 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
ย 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
ย 

More from BANSALANKIT1077

(1 point) The age distribution for senators in the 104th U-S- Congress.pdf
(1 point) The age distribution for senators in the 104th U-S- Congress.pdf(1 point) The age distribution for senators in the 104th U-S- Congress.pdf
(1 point) The age distribution for senators in the 104th U-S- Congress.pdfBANSALANKIT1077
ย 
(1 point) The combined math and verbal scores for females taking the S.pdf
(1 point) The combined math and verbal scores for females taking the S.pdf(1 point) The combined math and verbal scores for females taking the S.pdf
(1 point) The combined math and verbal scores for females taking the S.pdfBANSALANKIT1077
ย 
(1 point) In a survey of 269 people- the following data were obtained.pdf
(1 point) In a survey of 269 people- the following data were obtained.pdf(1 point) In a survey of 269 people- the following data were obtained.pdf
(1 point) In a survey of 269 people- the following data were obtained.pdfBANSALANKIT1077
ย 
(0) Assignment 4-11- Adding Cursor Flexibility An administration page.pdf
(0) Assignment 4-11- Adding Cursor Flexibility An administration page.pdf(0) Assignment 4-11- Adding Cursor Flexibility An administration page.pdf
(0) Assignment 4-11- Adding Cursor Flexibility An administration page.pdfBANSALANKIT1077
ย 
( 2 points) In a survey of 270 people- the following data were obtaine.pdf
( 2 points) In a survey of 270 people- the following data were obtaine.pdf( 2 points) In a survey of 270 people- the following data were obtaine.pdf
( 2 points) In a survey of 270 people- the following data were obtaine.pdfBANSALANKIT1077
ย 
(----IN C) Incorrect output on some test cases- I'm using a linked lis.pdf
(----IN C) Incorrect output on some test cases- I'm using a linked lis.pdf(----IN C) Incorrect output on some test cases- I'm using a linked lis.pdf
(----IN C) Incorrect output on some test cases- I'm using a linked lis.pdfBANSALANKIT1077
ย 
'ulcan Flyovers offers scenic overflights of Mount Saint Helens- the v.pdf
'ulcan Flyovers offers scenic overflights of Mount Saint Helens- the v.pdf'ulcan Flyovers offers scenic overflights of Mount Saint Helens- the v.pdf
'ulcan Flyovers offers scenic overflights of Mount Saint Helens- the v.pdfBANSALANKIT1077
ย 
'ear- What is the cost of common equity- Round your answer to two deci.pdf
'ear- What is the cost of common equity- Round your answer to two deci.pdf'ear- What is the cost of common equity- Round your answer to two deci.pdf
'ear- What is the cost of common equity- Round your answer to two deci.pdfBANSALANKIT1077
ย 
( information source - automotive trade body) Note- The information a.pdf
(  information source - automotive trade body) Note- The information a.pdf(  information source - automotive trade body) Note- The information a.pdf
( information source - automotive trade body) Note- The information a.pdfBANSALANKIT1077
ย 
'Sense giving' can also be referred to as- developing a recipe that th.pdf
'Sense giving' can also be referred to as- developing a recipe that th.pdf'Sense giving' can also be referred to as- developing a recipe that th.pdf
'Sense giving' can also be referred to as- developing a recipe that th.pdfBANSALANKIT1077
ย 
#2- Mary Decker- a 4-year-old who is covered under the CHIP program- p.pdf
#2- Mary Decker- a 4-year-old who is covered under the CHIP program- p.pdf#2- Mary Decker- a 4-year-old who is covered under the CHIP program- p.pdf
#2- Mary Decker- a 4-year-old who is covered under the CHIP program- p.pdfBANSALANKIT1077
ย 
#4 concepts of programming language question- (a) Explain the advantag.pdf
#4 concepts of programming language question- (a) Explain the advantag.pdf#4 concepts of programming language question- (a) Explain the advantag.pdf
#4 concepts of programming language question- (a) Explain the advantag.pdfBANSALANKIT1077
ย 
(2) Twelve major earthquakes on Richter mapnitades had shown here- Fin.pdf
(2) Twelve major earthquakes on Richter mapnitades had shown here- Fin.pdf(2) Twelve major earthquakes on Richter mapnitades had shown here- Fin.pdf
(2) Twelve major earthquakes on Richter mapnitades had shown here- Fin.pdfBANSALANKIT1077
ย 
## Part B- Conway's Game of Life ### Introduction John Conway's Ga.pdf
## Part B- Conway's Game of Life   ### Introduction   John Conway's Ga.pdf## Part B- Conway's Game of Life   ### Introduction   John Conway's Ga.pdf
## Part B- Conway's Game of Life ### Introduction John Conway's Ga.pdfBANSALANKIT1077
ย 
(2 pt) DNA transposons can be as short as 80bp- although the transposa.pdf
(2 pt) DNA transposons can be as short as 80bp- although the transposa.pdf(2 pt) DNA transposons can be as short as 80bp- although the transposa.pdf
(2 pt) DNA transposons can be as short as 80bp- although the transposa.pdfBANSALANKIT1077
ย 
(10 pts)- Let the random variable X have the following CDF- Find P(0X-.pdf
(10 pts)- Let the random variable X have the following CDF- Find P(0X-.pdf(10 pts)- Let the random variable X have the following CDF- Find P(0X-.pdf
(10 pts)- Let the random variable X have the following CDF- Find P(0X-.pdfBANSALANKIT1077
ย 
(10 peints) Given the Pceitional Liat clak belaw (implemented with a d.pdf
(10 peints) Given the Pceitional Liat clak belaw (implemented with a d.pdf(10 peints) Given the Pceitional Liat clak belaw (implemented with a d.pdf
(10 peints) Given the Pceitional Liat clak belaw (implemented with a d.pdfBANSALANKIT1077
ย 
(1) Briefly describe the terms sanitization- disinfection- sterilizati.pdf
(1) Briefly describe the terms sanitization- disinfection- sterilizati.pdf(1) Briefly describe the terms sanitization- disinfection- sterilizati.pdf
(1) Briefly describe the terms sanitization- disinfection- sterilizati.pdfBANSALANKIT1077
ย 
(1) Write out the POWER SET- Keep in mind a subset can be made of any.pdf
(1) Write out the POWER SET- Keep in mind a subset can be made of any.pdf(1) Write out the POWER SET- Keep in mind a subset can be made of any.pdf
(1) Write out the POWER SET- Keep in mind a subset can be made of any.pdfBANSALANKIT1077
ย 
(1) Question- Describe the five components of an Information System- (.pdf
(1) Question- Describe the five components of an Information System- (.pdf(1) Question- Describe the five components of an Information System- (.pdf
(1) Question- Describe the five components of an Information System- (.pdfBANSALANKIT1077
ย 

More from BANSALANKIT1077 (20)

(1 point) The age distribution for senators in the 104th U-S- Congress.pdf
(1 point) The age distribution for senators in the 104th U-S- Congress.pdf(1 point) The age distribution for senators in the 104th U-S- Congress.pdf
(1 point) The age distribution for senators in the 104th U-S- Congress.pdf
ย 
(1 point) The combined math and verbal scores for females taking the S.pdf
(1 point) The combined math and verbal scores for females taking the S.pdf(1 point) The combined math and verbal scores for females taking the S.pdf
(1 point) The combined math and verbal scores for females taking the S.pdf
ย 
(1 point) In a survey of 269 people- the following data were obtained.pdf
(1 point) In a survey of 269 people- the following data were obtained.pdf(1 point) In a survey of 269 people- the following data were obtained.pdf
(1 point) In a survey of 269 people- the following data were obtained.pdf
ย 
(0) Assignment 4-11- Adding Cursor Flexibility An administration page.pdf
(0) Assignment 4-11- Adding Cursor Flexibility An administration page.pdf(0) Assignment 4-11- Adding Cursor Flexibility An administration page.pdf
(0) Assignment 4-11- Adding Cursor Flexibility An administration page.pdf
ย 
( 2 points) In a survey of 270 people- the following data were obtaine.pdf
( 2 points) In a survey of 270 people- the following data were obtaine.pdf( 2 points) In a survey of 270 people- the following data were obtaine.pdf
( 2 points) In a survey of 270 people- the following data were obtaine.pdf
ย 
(----IN C) Incorrect output on some test cases- I'm using a linked lis.pdf
(----IN C) Incorrect output on some test cases- I'm using a linked lis.pdf(----IN C) Incorrect output on some test cases- I'm using a linked lis.pdf
(----IN C) Incorrect output on some test cases- I'm using a linked lis.pdf
ย 
'ulcan Flyovers offers scenic overflights of Mount Saint Helens- the v.pdf
'ulcan Flyovers offers scenic overflights of Mount Saint Helens- the v.pdf'ulcan Flyovers offers scenic overflights of Mount Saint Helens- the v.pdf
'ulcan Flyovers offers scenic overflights of Mount Saint Helens- the v.pdf
ย 
'ear- What is the cost of common equity- Round your answer to two deci.pdf
'ear- What is the cost of common equity- Round your answer to two deci.pdf'ear- What is the cost of common equity- Round your answer to two deci.pdf
'ear- What is the cost of common equity- Round your answer to two deci.pdf
ย 
( information source - automotive trade body) Note- The information a.pdf
(  information source - automotive trade body) Note- The information a.pdf(  information source - automotive trade body) Note- The information a.pdf
( information source - automotive trade body) Note- The information a.pdf
ย 
'Sense giving' can also be referred to as- developing a recipe that th.pdf
'Sense giving' can also be referred to as- developing a recipe that th.pdf'Sense giving' can also be referred to as- developing a recipe that th.pdf
'Sense giving' can also be referred to as- developing a recipe that th.pdf
ย 
#2- Mary Decker- a 4-year-old who is covered under the CHIP program- p.pdf
#2- Mary Decker- a 4-year-old who is covered under the CHIP program- p.pdf#2- Mary Decker- a 4-year-old who is covered under the CHIP program- p.pdf
#2- Mary Decker- a 4-year-old who is covered under the CHIP program- p.pdf
ย 
#4 concepts of programming language question- (a) Explain the advantag.pdf
#4 concepts of programming language question- (a) Explain the advantag.pdf#4 concepts of programming language question- (a) Explain the advantag.pdf
#4 concepts of programming language question- (a) Explain the advantag.pdf
ย 
(2) Twelve major earthquakes on Richter mapnitades had shown here- Fin.pdf
(2) Twelve major earthquakes on Richter mapnitades had shown here- Fin.pdf(2) Twelve major earthquakes on Richter mapnitades had shown here- Fin.pdf
(2) Twelve major earthquakes on Richter mapnitades had shown here- Fin.pdf
ย 
## Part B- Conway's Game of Life ### Introduction John Conway's Ga.pdf
## Part B- Conway's Game of Life   ### Introduction   John Conway's Ga.pdf## Part B- Conway's Game of Life   ### Introduction   John Conway's Ga.pdf
## Part B- Conway's Game of Life ### Introduction John Conway's Ga.pdf
ย 
(2 pt) DNA transposons can be as short as 80bp- although the transposa.pdf
(2 pt) DNA transposons can be as short as 80bp- although the transposa.pdf(2 pt) DNA transposons can be as short as 80bp- although the transposa.pdf
(2 pt) DNA transposons can be as short as 80bp- although the transposa.pdf
ย 
(10 pts)- Let the random variable X have the following CDF- Find P(0X-.pdf
(10 pts)- Let the random variable X have the following CDF- Find P(0X-.pdf(10 pts)- Let the random variable X have the following CDF- Find P(0X-.pdf
(10 pts)- Let the random variable X have the following CDF- Find P(0X-.pdf
ย 
(10 peints) Given the Pceitional Liat clak belaw (implemented with a d.pdf
(10 peints) Given the Pceitional Liat clak belaw (implemented with a d.pdf(10 peints) Given the Pceitional Liat clak belaw (implemented with a d.pdf
(10 peints) Given the Pceitional Liat clak belaw (implemented with a d.pdf
ย 
(1) Briefly describe the terms sanitization- disinfection- sterilizati.pdf
(1) Briefly describe the terms sanitization- disinfection- sterilizati.pdf(1) Briefly describe the terms sanitization- disinfection- sterilizati.pdf
(1) Briefly describe the terms sanitization- disinfection- sterilizati.pdf
ย 
(1) Write out the POWER SET- Keep in mind a subset can be made of any.pdf
(1) Write out the POWER SET- Keep in mind a subset can be made of any.pdf(1) Write out the POWER SET- Keep in mind a subset can be made of any.pdf
(1) Write out the POWER SET- Keep in mind a subset can be made of any.pdf
ย 
(1) Question- Describe the five components of an Information System- (.pdf
(1) Question- Describe the five components of an Information System- (.pdf(1) Question- Describe the five components of an Information System- (.pdf
(1) Question- Describe the five components of an Information System- (.pdf
ย 

Recently uploaded

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
ย 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
ย 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
ย 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
ย 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
ย 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
ย 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
ย 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
ย 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
ย 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
ย 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
ย 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
ย 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
ย 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
ย 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
ย 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
ย 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
ย 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
ย 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
ย 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
ย 

Recently uploaded (20)

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
ย 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
ย 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
ย 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
ย 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
ย 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
ย 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
ย 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
ย 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
ย 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
ย 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
ย 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
ย 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
ย 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
ย 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
ย 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
ย 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
ย 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
ย 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
ย 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
ย 

#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf

  • 1. #include <algorithm> #include <cstdlib> #include <iostream> #include <iterator> /************************************************************/ // Local includes /************************************************************/ // Using declarations // YOU DO NOT NECESSARILY NEED TO USE ALL OF THESE! using std::copy; using std::copy_backward; using std::distance; using std::fill; using std::ostream; using std::ptrdiff_t; /************************************************************/ template<typename T> class Array { public: //***************************************************** // DO NOT MODIFY THIS SECTION! // Some standard Container type aliases
  • 2. 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; //***************************************************** // Default ctor. // Initialize an empty Array. // This method is complete, and does NOT need modification. // Remember to use a _member initialization list_ for each ctor, // like I have below for the default ctor. Array () : m_size (0), m_capacity (0), m_array (nullptr) { } // Size ctor. // Initialize an Array of size "pSize", with each element // set to "value".
  • 3. explicit Array (size_t pSize, const T& value = T ()) : m_size (pSize), m_capacity (pSize), m_array (new T[m_capacity]) { fill (begin (), end (), value); } // TODO! // Range ctor. // Initialize an Array from the range [first, last). // "first" and "last" must be Array iterators or pointers // into a primitive array. Array (const_iterator first, const_iterator last) :m_size(distance(first,last)),m_capacity(m_size),m_array(new T[m_capacity]) { copy(first,last,m_array); } // TODO! // Copy ctor. // Initialize this object from "a". Array (const Array& a) :m_size(a.m_size),m_capacity(a.m_capacity),m_array(new T[m_capacity]) {
  • 4. copy(a.begin(),a.end(),m_array); } // TODO! // Destructor. // Release allocated memory. ~Array () { delete[] m_array; } // TODO! // Assignment operator. // Assign "a" to this object. // Be careful to check for self-assignment. Array& operator= (const Array& a) { if (this != &a) { delete[] m_array; m_size = a.m_size; m_capacity = a.m_capacity; m_array = new T[m_capacity]; copy(a.begin(),a.end(),m_array);
  • 5. } return *this; } // Return the size. size_t size () const { return m_size; } // TODO! // Return true if this Array is empty, false o/w. bool empty () const { return m_size == 0; } // TODO! // Return the capacity. size_t capacity () const { return m_capacity; }
  • 6. // TODO! // Return the element at position "index". T& operator[] (size_t index) { return m_array[index]; } // TODO! const T& operator[] (size_t index) const { return m_array[index]; } // TODO! // Insert an element at the back. // If the capacity is insufficient, DOUBLE it. // If the capacity is 0, increase it to 1. void push_back (const T& item) { if (m_size == 0) { m_capacity = 1; m_array = new T[m_capacity]; }
  • 7. else if (m_size == m_capacity) { m_capacity *= 2; T* temp = new T[2 * m_capacity]; copy(begin(),end(),temp); delete[] m_array; m_array = temp; } m_array[m_size] = item; ++m_size; } // TODO! // Erase the element at the back. void pop_back () { if (m_size > 0) { --m_size; } } // Reserve capacity for "space" elements. // "space" must be greater than capacity.
  • 8. // 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 ()) {
  • 9. if (newSize == m_size) { return; } if (newSize < m_size) { m_size = newSize; return; } if (newSize > m_capacity) { reserve(newSize); } fill (begin (), end (), value); m_size = newSize; } // 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)
  • 10. { } // TODO! // Remove element at "pos", and return an iterator // referencing the next element. iterator erase (iterator pos) { copy(pos + 1, end(), pos); -- m_size; return pos; } // TODO! // Return iterator pointing to the first element. iterator begin () { return m_array; } // TODO! const_iterator begin () const {
  • 11. return m_array; } // TODO! // Return iterator pointing one beyond the last element. iterator end () { return m_array + m_size; } // TODO! const_iterator end () const { return m_array + m_size; } // Return a pointer to the underlying dynamic array T* data () { return m_array; } // Return a pointer to the underlying dynamic array T const*
  • 12. data () const { return m_array; } 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; }; Fix the below error with the member function resize: Help with iterator insert (iterator pos, const T& item) { }