This repository has been archived by the owner on Dec 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
vector
JlXip edited this page May 4, 2020
·
4 revisions
-
Class name:
vector
-
Short description:
vector
implements a dynamic array which autoresizes. - Has iterator: yes.
T
is the data type of the elements.
Name | Returns | Const | Description | Efficiency (worst case) | Efficiency (mid case) | Efficiency (best case) |
---|---|---|---|---|---|---|
vector() |
N/A | NO | Default constructor. Initializes an empty array. | O(1) | O(1) | O(1) |
vector(const vector<T>& other) |
N/A | NO | Copy constructor. Constructs the vector as a copy from another one. | O(n) | O(n) | O(n) |
vector(vector<T>&& other) |
N/A | NO | Moves a vector to the created object, leaving the other one unusable. |
O(1) | O(1) | O(1) |
~vector() |
N/A | NO | Destructor. | O(1) | O(1) | O(1) |
size() |
size_t |
YES | Returns the number of inserted elements. | O(1) | O(1) | O(1) |
disp_right(size_t idx, size_t count) |
NO | NO | Displaces count elements to the right, starting from idx . Might overwrite. |
O(n²) | O(n) | O(n) |
disp_left(size_t idx, size_t count) |
NO | NO | Displaces count elements to the left, starting from idx . Might overwrite. |
O(n) | O(n) | O(n) |
push_back(T e) |
NO | NO | Appends an element at the end, reallocating if necessary. | O(n) | O(1) | O(1) |
push_back(const vector<T>& other) |
NO | NO | Appends the elements of other at the end, reallocating if necessary. |
O(n²) | O(n²) | O(n) |
pop_back() |
NO | NO | Removes the last element. | O(1) | O(1) | O(1) |
back() |
T& |
NO | Returns the last element. | O(1) | O(1) | O(1) |
back() |
const T& |
YES | Returns the last element. | O(1) | O(1) | O(1) |
push_front(T e) |
NO | NO | Inserts an element at the beginning. | O(n²) | O(n) | O(n) |
pop_front() |
NO | NO | Removes the first element. | O(n) | O(n) | O(n) |
front() |
T& |
NO | Returns the first element. | O(1) | O(1) | O(1) |
front() |
const T& |
YES | Returns the first element. | O(1) | O(1) | O(1) |
invert() |
NO | NO | Inverts the order of the elements. | O(n) | O(n) | O(n) |
clear() |
NO | NO | Leaves the vector empty. | O(1) | O(1) | O(1) |
operator=(const vector<T>& other) |
vector<T>& |
NO | Assignment operator. | O(n) | O(n) | O(n) |
operator=(vector<T>&& other) |
vector<T>& |
NO | Move operator. | O(1) | O(1) | O(1) |
operator[](size_t idx) |
T& |
NO | Returns the element at position idx. | O(1) | O(1) | O(1) |
operator[](size_t idx) |
const T& |
NO | Returns the element at position idx. | O(1) | O(1) | O(1) |
operator==(const vector<T>& other) |
bool |
YES | Compares each element individually. Returns at the first mismatch. | O(n) | O(n) | O(1) |
operator!=(const vector<T>& other) |
bool |
YES | Compares each individual element. Returns at the first mismatch. | O(n) | O(n) | O(1) |
operator+=(const vector<T>& other) |
vector<T>& |
NO | Equivalent to push_back(const vector<T>& other) . |
O(n²) | O(n²) | O(n) |