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

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhleson0603
 

Recently uploaded (20)

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 

#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) { }