SlideShare a Scribd company logo
1 of 11
Download to read offline
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);
}
// 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);
}
// 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);
}
// Destructor.
// Release allocated memory.
~Array ()
{
delete[] m_array;
}
// Assignment operator.
// Assign "a" to this object.
// Be careful to check for self-assignment.
Array&
operator= (const Array& a)
{
if (this != &a)
{
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;
}
// Return true if this Array is empty, false o/w.
bool
empty () const
{
return m_size == 0;
}
// Return the capacity.
size_t
capacity () const
{
return m_capacity;
}
// Return the element at position "index".
T& operator[] (size_t index)
{
return m_array[index];
}
const T& operator[] (size_t index) const
{
return m_array[index];
}
// 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;
}
// 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;
}
}
// 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;
}
// 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)
{
}
// 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;
}
// Return iterator pointing to the first element.
iterator
begin ()
{
return m_array;
}
const_iterator
begin () const
{
return m_array;
}
// Return iterator pointing one beyond the last element.
iterator
end ()
{
return m_array + m_size;
}
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;
};
Test this custom vector class "Array" to see if the code works and help with
iterator
insert (iterator pos, const T& item)
{
}
please!

More Related Content

Similar to template-typename T- class Array { public- ---------------------------.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 steviesellars
 
@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
 
Everything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdfEverything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdffirstchoiceajmer
 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdffcaindore
 
helpInstructionsAdd the function max as an abstract function to .pdf
helpInstructionsAdd the function max as an abstract function to .pdfhelpInstructionsAdd the function max as an abstract function to .pdf
helpInstructionsAdd the function max as an abstract function to .pdfalmonardfans
 
include ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfinclude ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfnaslin841216
 
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
 
#include stdafx.h#include iostreamusing namespace std;cl.pdf
#include stdafx.h#include iostreamusing namespace std;cl.pdf#include stdafx.h#include iostreamusing namespace std;cl.pdf
#include stdafx.h#include iostreamusing namespace std;cl.pdfaashwini4
 
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
 
Given the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfGiven the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfNicholasflqStewartl
 
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
 
Please fix my errors class Iterator public Construc.pdf
Please fix my errors   class Iterator  public  Construc.pdfPlease fix my errors   class Iterator  public  Construc.pdf
Please fix my errors class Iterator public Construc.pdfkitty811
 
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
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
Modifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdfModifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdfLalkamal2
 
include ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfinclude ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfaathmiboutique
 
Header file for an array-based implementation of the ADT bag. @f.pdf
 Header file for an array-based implementation of the ADT bag. @f.pdf Header file for an array-based implementation of the ADT bag. @f.pdf
Header file for an array-based implementation of the ADT bag. @f.pdfsudhirchourasia86
 
Can you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdfCan you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdfFashionBoutiquedelhi
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfcallawaycorb73779
 

Similar to template-typename T- class Array { public- ---------------------------.pdf (20)

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
 
@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
 
Everything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdfEverything needs to be according to the instructions- thank you! SUPPO.pdf
Everything needs to be according to the instructions- thank you! SUPPO.pdf
 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdf
 
helpInstructionsAdd the function max as an abstract function to .pdf
helpInstructionsAdd the function max as an abstract function to .pdfhelpInstructionsAdd the function max as an abstract function to .pdf
helpInstructionsAdd the function max as an abstract function to .pdf
 
include ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfinclude ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdf
 
Link list
Link listLink list
Link list
 
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
 
#include stdafx.h#include iostreamusing namespace std;cl.pdf
#include stdafx.h#include iostreamusing namespace std;cl.pdf#include stdafx.h#include iostreamusing namespace std;cl.pdf
#include stdafx.h#include iostreamusing namespace std;cl.pdf
 
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
 
Given the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.pdfGiven the following errors and class in Java- How are these errors fix.pdf
Given the following errors and class in Java- How are these errors fix.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
 
Please fix my errors class Iterator public Construc.pdf
Please fix my errors   class Iterator  public  Construc.pdfPlease fix my errors   class Iterator  public  Construc.pdf
Please fix my errors class Iterator public Construc.pdf
 
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
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
Modifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdfModifications highlighted in bold lettersDropOutStack.javaim.pdf
Modifications highlighted in bold lettersDropOutStack.javaim.pdf
 
include ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdfinclude ltfunctionalgt include ltiteratorgt inclu.pdf
include ltfunctionalgt include ltiteratorgt inclu.pdf
 
Header file for an array-based implementation of the ADT bag. @f.pdf
 Header file for an array-based implementation of the ADT bag. @f.pdf Header file for an array-based implementation of the ADT bag. @f.pdf
Header file for an array-based implementation of the ADT bag. @f.pdf
 
Can you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdfCan you please debug this Thank you in advance! This program is sup.pdf
Can you please debug this Thank you in advance! This program is sup.pdf
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
 

More from ashokadyes

Terando Center began operations on July 1 - It uses a perpetual invent (1).pdf
Terando Center began operations on July 1 - It uses a perpetual invent (1).pdfTerando Center began operations on July 1 - It uses a perpetual invent (1).pdf
Terando Center began operations on July 1 - It uses a perpetual invent (1).pdfashokadyes
 
Television and radio stations use four call letters starting with W or.pdf
Television and radio stations use four call letters starting with W or.pdfTelevision and radio stations use four call letters starting with W or.pdf
Television and radio stations use four call letters starting with W or.pdfashokadyes
 
Tesla made an investment in China- Below are the cash flows (in billio.pdf
Tesla made an investment in China- Below are the cash flows (in billio.pdfTesla made an investment in China- Below are the cash flows (in billio.pdf
Tesla made an investment in China- Below are the cash flows (in billio.pdfashokadyes
 
Term for a microbe that can grow in the ocean- an estuary- and a river.pdf
Term for a microbe that can grow in the ocean- an estuary- and a river.pdfTerm for a microbe that can grow in the ocean- an estuary- and a river.pdf
Term for a microbe that can grow in the ocean- an estuary- and a river.pdfashokadyes
 
TB MC Qu- 90 Assume you can exchange-- Mised chorer perse tin64 5t321.pdf
TB MC Qu- 90 Assume you can exchange-- Mised chorer perse tin64 5t321.pdfTB MC Qu- 90 Assume you can exchange-- Mised chorer perse tin64 5t321.pdf
TB MC Qu- 90 Assume you can exchange-- Mised chorer perse tin64 5t321.pdfashokadyes
 
TB MC Qu- 01-34 What is substantive law- What is substantive law- Mult.pdf
TB MC Qu- 01-34 What is substantive law- What is substantive law- Mult.pdfTB MC Qu- 01-34 What is substantive law- What is substantive law- Mult.pdf
TB MC Qu- 01-34 What is substantive law- What is substantive law- Mult.pdfashokadyes
 
Television- newspapers- the Internet- and magazines are just a few of.pdf
Television- newspapers- the Internet- and magazines are just a few of.pdfTelevision- newspapers- the Internet- and magazines are just a few of.pdf
Television- newspapers- the Internet- and magazines are just a few of.pdfashokadyes
 
The Achilles heel (or biggest disadvantage-danger-pitfall) of relying.pdf
The Achilles heel (or biggest disadvantage-danger-pitfall) of relying.pdfThe Achilles heel (or biggest disadvantage-danger-pitfall) of relying.pdf
The Achilles heel (or biggest disadvantage-danger-pitfall) of relying.pdfashokadyes
 
Task environments can take on several different characteristics- Match.pdf
Task environments can take on several different characteristics- Match.pdfTask environments can take on several different characteristics- Match.pdf
Task environments can take on several different characteristics- Match.pdfashokadyes
 
Telsa issues Fixed- Intel Issues floating- bp is basis point (100 bp i.pdf
Telsa issues Fixed- Intel Issues floating- bp is basis point (100 bp i.pdfTelsa issues Fixed- Intel Issues floating- bp is basis point (100 bp i.pdf
Telsa issues Fixed- Intel Issues floating- bp is basis point (100 bp i.pdfashokadyes
 
TB MC Qu- 13-76 Genesis Scents has two divisions- the Cologne--- price.pdf
TB MC Qu- 13-76 Genesis Scents has two divisions- the Cologne--- price.pdfTB MC Qu- 13-76 Genesis Scents has two divisions- the Cologne--- price.pdf
TB MC Qu- 13-76 Genesis Scents has two divisions- the Cologne--- price.pdfashokadyes
 
TechPro Inc-- a leading laptop manufacturing company- manufactures all.pdf
TechPro Inc-- a leading laptop manufacturing company- manufactures all.pdfTechPro Inc-- a leading laptop manufacturing company- manufactures all.pdf
TechPro Inc-- a leading laptop manufacturing company- manufactures all.pdfashokadyes
 
The acoompanying table describes resulls from groups of 8 births from.pdf
The acoompanying table describes resulls from groups of 8 births from.pdfThe acoompanying table describes resulls from groups of 8 births from.pdf
The acoompanying table describes resulls from groups of 8 births from.pdfashokadyes
 
The accompanying unions and labor law data reports the percent of publ.pdf
The accompanying unions and labor law data reports the percent of publ.pdfThe accompanying unions and labor law data reports the percent of publ.pdf
The accompanying unions and labor law data reports the percent of publ.pdfashokadyes
 
The ability for a company to meet its liability obligations is importa.pdf
The ability for a company to meet its liability obligations is importa.pdfThe ability for a company to meet its liability obligations is importa.pdf
The ability for a company to meet its liability obligations is importa.pdfashokadyes
 
The accompanying table describes the random variable x- the numbers of (1).pdf
The accompanying table describes the random variable x- the numbers of (1).pdfThe accompanying table describes the random variable x- the numbers of (1).pdf
The accompanying table describes the random variable x- the numbers of (1).pdfashokadyes
 
Task- Review the medical documentation for the patient progress notes.pdf
Task- Review the medical documentation for the patient progress notes.pdfTask- Review the medical documentation for the patient progress notes.pdf
Task- Review the medical documentation for the patient progress notes.pdfashokadyes
 
The ABO human blood types are due to the presence of carbohydrates on.pdf
The ABO human blood types are due to the presence of carbohydrates on.pdfThe ABO human blood types are due to the presence of carbohydrates on.pdf
The ABO human blood types are due to the presence of carbohydrates on.pdfashokadyes
 
The Abstraction of address spaces- Now run pmap on some of these proce.pdf
The Abstraction of address spaces- Now run pmap on some of these proce.pdfThe Abstraction of address spaces- Now run pmap on some of these proce.pdf
The Abstraction of address spaces- Now run pmap on some of these proce.pdfashokadyes
 
The above case study highlighted the rise of trade unions in South Afr.pdf
The above case study highlighted the rise of trade unions in South Afr.pdfThe above case study highlighted the rise of trade unions in South Afr.pdf
The above case study highlighted the rise of trade unions in South Afr.pdfashokadyes
 

More from ashokadyes (20)

Terando Center began operations on July 1 - It uses a perpetual invent (1).pdf
Terando Center began operations on July 1 - It uses a perpetual invent (1).pdfTerando Center began operations on July 1 - It uses a perpetual invent (1).pdf
Terando Center began operations on July 1 - It uses a perpetual invent (1).pdf
 
Television and radio stations use four call letters starting with W or.pdf
Television and radio stations use four call letters starting with W or.pdfTelevision and radio stations use four call letters starting with W or.pdf
Television and radio stations use four call letters starting with W or.pdf
 
Tesla made an investment in China- Below are the cash flows (in billio.pdf
Tesla made an investment in China- Below are the cash flows (in billio.pdfTesla made an investment in China- Below are the cash flows (in billio.pdf
Tesla made an investment in China- Below are the cash flows (in billio.pdf
 
Term for a microbe that can grow in the ocean- an estuary- and a river.pdf
Term for a microbe that can grow in the ocean- an estuary- and a river.pdfTerm for a microbe that can grow in the ocean- an estuary- and a river.pdf
Term for a microbe that can grow in the ocean- an estuary- and a river.pdf
 
TB MC Qu- 90 Assume you can exchange-- Mised chorer perse tin64 5t321.pdf
TB MC Qu- 90 Assume you can exchange-- Mised chorer perse tin64 5t321.pdfTB MC Qu- 90 Assume you can exchange-- Mised chorer perse tin64 5t321.pdf
TB MC Qu- 90 Assume you can exchange-- Mised chorer perse tin64 5t321.pdf
 
TB MC Qu- 01-34 What is substantive law- What is substantive law- Mult.pdf
TB MC Qu- 01-34 What is substantive law- What is substantive law- Mult.pdfTB MC Qu- 01-34 What is substantive law- What is substantive law- Mult.pdf
TB MC Qu- 01-34 What is substantive law- What is substantive law- Mult.pdf
 
Television- newspapers- the Internet- and magazines are just a few of.pdf
Television- newspapers- the Internet- and magazines are just a few of.pdfTelevision- newspapers- the Internet- and magazines are just a few of.pdf
Television- newspapers- the Internet- and magazines are just a few of.pdf
 
The Achilles heel (or biggest disadvantage-danger-pitfall) of relying.pdf
The Achilles heel (or biggest disadvantage-danger-pitfall) of relying.pdfThe Achilles heel (or biggest disadvantage-danger-pitfall) of relying.pdf
The Achilles heel (or biggest disadvantage-danger-pitfall) of relying.pdf
 
Task environments can take on several different characteristics- Match.pdf
Task environments can take on several different characteristics- Match.pdfTask environments can take on several different characteristics- Match.pdf
Task environments can take on several different characteristics- Match.pdf
 
Telsa issues Fixed- Intel Issues floating- bp is basis point (100 bp i.pdf
Telsa issues Fixed- Intel Issues floating- bp is basis point (100 bp i.pdfTelsa issues Fixed- Intel Issues floating- bp is basis point (100 bp i.pdf
Telsa issues Fixed- Intel Issues floating- bp is basis point (100 bp i.pdf
 
TB MC Qu- 13-76 Genesis Scents has two divisions- the Cologne--- price.pdf
TB MC Qu- 13-76 Genesis Scents has two divisions- the Cologne--- price.pdfTB MC Qu- 13-76 Genesis Scents has two divisions- the Cologne--- price.pdf
TB MC Qu- 13-76 Genesis Scents has two divisions- the Cologne--- price.pdf
 
TechPro Inc-- a leading laptop manufacturing company- manufactures all.pdf
TechPro Inc-- a leading laptop manufacturing company- manufactures all.pdfTechPro Inc-- a leading laptop manufacturing company- manufactures all.pdf
TechPro Inc-- a leading laptop manufacturing company- manufactures all.pdf
 
The acoompanying table describes resulls from groups of 8 births from.pdf
The acoompanying table describes resulls from groups of 8 births from.pdfThe acoompanying table describes resulls from groups of 8 births from.pdf
The acoompanying table describes resulls from groups of 8 births from.pdf
 
The accompanying unions and labor law data reports the percent of publ.pdf
The accompanying unions and labor law data reports the percent of publ.pdfThe accompanying unions and labor law data reports the percent of publ.pdf
The accompanying unions and labor law data reports the percent of publ.pdf
 
The ability for a company to meet its liability obligations is importa.pdf
The ability for a company to meet its liability obligations is importa.pdfThe ability for a company to meet its liability obligations is importa.pdf
The ability for a company to meet its liability obligations is importa.pdf
 
The accompanying table describes the random variable x- the numbers of (1).pdf
The accompanying table describes the random variable x- the numbers of (1).pdfThe accompanying table describes the random variable x- the numbers of (1).pdf
The accompanying table describes the random variable x- the numbers of (1).pdf
 
Task- Review the medical documentation for the patient progress notes.pdf
Task- Review the medical documentation for the patient progress notes.pdfTask- Review the medical documentation for the patient progress notes.pdf
Task- Review the medical documentation for the patient progress notes.pdf
 
The ABO human blood types are due to the presence of carbohydrates on.pdf
The ABO human blood types are due to the presence of carbohydrates on.pdfThe ABO human blood types are due to the presence of carbohydrates on.pdf
The ABO human blood types are due to the presence of carbohydrates on.pdf
 
The Abstraction of address spaces- Now run pmap on some of these proce.pdf
The Abstraction of address spaces- Now run pmap on some of these proce.pdfThe Abstraction of address spaces- Now run pmap on some of these proce.pdf
The Abstraction of address spaces- Now run pmap on some of these proce.pdf
 
The above case study highlighted the rise of trade unions in South Afr.pdf
The above case study highlighted the rise of trade unions in South Afr.pdfThe above case study highlighted the rise of trade unions in South Afr.pdf
The above case study highlighted the rise of trade unions in South Afr.pdf
 

Recently uploaded

Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
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
 
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
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
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
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
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
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
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
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 

Recently uploaded (20)

Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
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
 
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
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
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
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
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
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
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
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
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
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 

template-typename T- class Array { public- ---------------------------.pdf

  • 1. 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),
  • 2. 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); } // 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); }
  • 3. // 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); } // Destructor. // Release allocated memory. ~Array () { delete[] m_array; } // Assignment operator. // Assign "a" to this object. // Be careful to check for self-assignment. Array& operator= (const Array& a) { if (this != &a) { m_size = a.m_size; m_capacity = a.m_capacity;
  • 4. 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; } // Return true if this Array is empty, false o/w. bool empty () const { return m_size == 0; } // Return the capacity. size_t capacity () const { return m_capacity; }
  • 5. // Return the element at position "index". T& operator[] (size_t index) { return m_array[index]; } const T& operator[] (size_t index) const { return m_array[index]; } // 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;
  • 6. T* temp = new T[2 * m_capacity]; copy(begin(),end(),temp); delete[] m_array; m_array = temp; } m_array[m_size] = item; ++m_size; } // 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)
  • 7. { if (space > capacity ()) { T* array = new T[space]; copy (begin (), end (), array); delete[] m_array; m_array = array; m_capacity = space; } } // 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)
  • 8. { m_size = newSize; return; } if (newSize > m_capacity) { reserve(newSize); } fill (begin (), end (), value); m_size = newSize; } // 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) { } // Remove element at "pos", and return an iterator // referencing the next element. iterator erase (iterator pos)
  • 9. { copy(pos + 1, end(), pos); -- m_size; return pos; } // Return iterator pointing to the first element. iterator begin () { return m_array; } const_iterator begin () const { return m_array; } // Return iterator pointing one beyond the last element. iterator end () { return m_array + m_size; } const_iterator
  • 10. 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;
  • 11. }; Test this custom vector class "Array" to see if the code works and help with iterator insert (iterator pos, const T& item) { } please!