-
Notifications
You must be signed in to change notification settings - Fork 0
Vector
- Vector();
- Vector(unsigned int size,TYPE value);
- ~Vector();
- void push_back(T element);
- TYPE pop_back();
- TYPE& operator[](unsigned int pos);
- Vector &operator=(Vector &vec);
- Vector &operator+=(Vector &vec);
- unsigned int size();
- void resize(unsigned int size);
- unsigned int capacity();
- void erase(unsigned int pos,unsigned int amount = 1);
- void clear();
- TYPE* begin();
- TYPE* end();
- Constructor
- size predefined a size of the Array
- No parameter will initialize the arraysize = 0
Vector<int> myVector;
Vector<String> myVector;
- You can choose any type as a Vector
- Deletes all saved data in the array.
delete &myVector;
- Adds an element to the array.
myVector.push_back(15);
- Returns the last last element of the array.
- Deletes the last element in the array.
- Decreses the size of the array.
int value = myVector.pop_back();
- Returns the element of the array at pos.
- If the pos is grater than the size of the array, it returns the pos % size.
- If the size is 5, and pos is 7 than it returns element 2
int value = myVector[0]
This gets the first element of the array
int value = myVector[3]
This gets the fourth element of the array
int value = myVector[myVector.size()-1]
This gets the last element of the array
- Makes the left vector equal the right vector.
- Both vectors have to be the same type.
Vector<int> newVector = myVector;
- Copys the right vector to the end of the left vector.
- Both vectors have to be the same type.
newVector += myVector;
- Gets the size of the array.
unsigned int size = myVector.size();
- Resizes the array.
- Used to make the push_back() faster.
- Reservs storage for size elements.
myVector.resize(10);
- returns the actual size of the array which is reserved in storage.
When an element is pushed back the size won't increase until capacity <= size.
Vector<int> myVector;
myVector.resize(5);
myVector.size() == 0
myVector.capacity() == 5
myVector.push_back(1);
myVector.size() == 1
myVector.capacity() == 5
- Erase a sequence of elements in the array.
- Beginning from element pos.
- From there on deletes amount elements.
myVector.erase(2,3);
Erases the elements: [-]: [x][x][-][-][-][x][x]
myVector.erase(2);
Erases the element: [-]: [x][x][-][x][x][x][x]
- Clears the whole array.
- All elements get deleted.
myVector.clear();
- Gets the pointer of the first element in the array.
-
Don't use it in
myVector.erase(myVector.begin());
int *p_int = myVector.begin();
- Gets the pointer of the last element in the array.
-
Don't use it in
myVector.erase(myVector.end());
int *p_int = myVector.end();
Wiki
Arduino libraries