#include <vector.h>
template<typename T>
class Vector< T >
Implementation of a resizable Vector ADT using a dynamically allocated C-style array.
- Author
- Mark Maloof (maloo.nosp@m.f@cs.nosp@m..geor.nosp@m.geto.nosp@m.wn.ed.nosp@m.u)
- Version
- 1.3, 05/07/13
-
1.4, 01/08/20
Default constructor. Constructs an empty vector with an initial capacity of ten. Indirectly throws bad_alloc if new fails to allocate memory.
- Exceptions
-
bad_alloc | if memory cannot be allocated |
Constructor for initializing an empty vector with a specified capacity. Indirectly throws bad_alloc if new fails to allocate memory.
- Parameters
-
cap | the capacity of the vector |
- Exceptions
-
bad_alloc | if memory cannot be allocated |
Constructor for initializing a vector to an initial size with its components initialized to a specified object. Indirectly throws bad_alloc if new fails to allocate memory.
- Parameters
-
sz | the size of the vector |
object | the initial object for the components |
- Exceptions
-
bad_alloc | if memory cannot be allocated |
Copy constructor. Makes a deep copy of the specified vector. Indirectly throws bad_alloc if new fails to allocate memory.
- Parameters
-
vector | the vector to be copied |
- Exceptions
-
bad_alloc | if memory cannot be allocated |
template<typename T >
void Vector< T >::assign |
( |
const unsigned |
i, |
|
|
const T & |
object |
|
) |
| |
Assigns the object to the specified position in this vector. Directly throws out_of_range if the specified position is out of range.
- Parameters
-
i | the position to be assigned. |
object | the object to be stored in this vector. |
- Exceptions
-
out_of_range | if the position is out of bounds. |
template<typename T >
T & Vector< T >::at |
( |
const unsigned |
i | ) |
const |
Returns a reference to the object stored at a given position in this vector. Directly throws out_of_range if the specified position is out of range.
- Parameters
-
- Returns
- a reference to the object.
- Exceptions
-
out_of_range | if the position is out of bounds. |
template<typename T >
unsigned Vector< T >::capacity |
( |
| ) |
const |
Returns the capacity of the vector, which is the number of elements that the vector can store before increasing its capacity.
- Returns
- an unsigned integer indicating the vector's capacity.
Removes the elements of the vector.
template<typename T >
bool Vector< T >::empty |
( |
| ) |
const |
Returns true if the vector is empty; returns false otherwise.
- Returns
- true if empty; false otherwise.
template<typename T >
void Vector< T >::increaseCapacity |
( |
| ) |
|
|
private |
Increases the capacity of the vector by doubling its current capacity. Indirectly throws bad_alloc if new fails to allocate memory.
- Exceptions
-
bad_alloc | if memory cannot be allocated. |
template<typename T >
void Vector< T >::insert |
( |
const unsigned |
i, |
|
|
const T & |
object |
|
) |
| |
Inserts the object at the given position. Increases capacity if necessary. Indirectly throws bad_alloc if new fails to allocate memory. Directly throws out_of_range if the specified position is out of range.
- Parameters
-
i | the position of insertion. |
object | the object to be inserted. |
- Exceptions
-
bad_alloc | if memory cannot be allocated. |
out_of_range | if index parameter is out of bounds. |
Returns a deep copy of the vector passed in as the parameter. Indirectly throws bad_alloc if new fails to allocate memory.
- Parameters
-
vector | the vector to be copied. |
- Returns
- a copy of the vector.
- Exceptions
-
bad_alloc | if memory cannot be allocated. |
template<typename T >
T & Vector< T >::operator[] |
( |
const unsigned |
i | ) |
const |
Returns a reference to the object stored at a given position in this vector. Directly throws out_of_range if the specified position is out of range.
- Parameters
-
- Returns
- a reference to the object.
- Exceptions
-
out_of_range | if the position is out of bounds. |
template<typename T >
void Vector< T >::push_back |
( |
const T & |
object | ) |
|
Adds the object to the end of the vector. Increases capacity if necessary. Indirectly throws bad_alloc if new fails to allocate memory.
- Parameters
-
object | the object to be added to the end of the vector. |
- Exceptions
-
bad_alloc | if memory cannot be allocated. |
template<typename T >
void Vector< T >::remove |
( |
const unsigned |
i | ) |
|
Removes the object stored in the given position. Directly throws out_of_range if the specified position is out of range.
- Parameters
-
i | the position of removal. |
- Exceptions
-
out_of_range | if the position is out of bounds. |
template<typename T >
void Vector< T >::resize |
( |
const unsigned |
newSize, |
|
|
const T & |
object = T() |
|
) |
| |
Resizes the vector to its new size. After allocating new memory and copy the contents of old memory, stores the object in any unassigned locations. Indirectly throws bad_alloc if new fails to allocate memory.
- Parameters
-
newSize | the new size of the vector |
object | the object for any new, unassigned locations |
- Exceptions
-
bad_alloc | if memory cannot be allocated |
template<typename T >
unsigned Vector< T >::size |
( |
| ) |
const |
Returns the size (i.e., the number of elements) of the vector.
- Returns
- an unsigned integer indicating the vector's size.
Sorts the elements of this vector in ascending order.
the capacity of this vector
the contents of this vector
The documentation for this class was generated from the following file: