General
A vector is a resizable array. Like arrays, vectors uses contiguous storage of their elements in memory. the [] operator works
the same as they do for arrays; they can be used to access elements. In order to use vectors, the vector library
needs to be included in the header.
The syntax for using vectors is:
vector <data_type> variable_name;
Within the brackets, <>, is any data type such as int, char, strings, or objects. It can be any data type either compound or primative types.
declares a empty vector x of integers.
declares a vector y of integers with a size of 10 and all elements initialize to 0.
declares a vector z of integers with a size of 5 and all elements initialize to 3.
Functions
There are 4 main funcations for vectors:
- .size() - returns the size of the vector
- .pop_back() - remove the last element, decrease the size by 1
- .push_back() - add element to the end, increase the size by 1
- .back() - returns the last value of the vector