Different Functions associated with Vectors


There are lots of inbuilt functions which is used on a vector to modify it, to get an iterator from it, to access an element from it and finally some utility functions. We are going to see the mostly used function of each kind - 


A. Vector Modifier Functions:

    1. assign() : It assign new values in the vector replacing the old ones.

        2. push_back() : It pushes a new values at the right end of the vector.

        3. pop_back() : It deletes the last element from the right end of the vector.

        4. insert() : It inserts a new element before the specified position in the vector.

        5. erase() : It removes the element or the elements in range from the vector.

        6. clear() : It removes all the elements from the vector and make it empty.



B. Functions returning iterators:

    1. begin() : returns an iterator pointing at the first element of the vector.

        2. end() : returns an iterator pointing to the theoretical element after the last element.

        3. rbegin() : returns an reverse iterator pointing the last element of vector.

        4. rend() : returns an iterator pointing to the theoretical element before the first                                     element.

        



C. Functions for accessing elements:

    1. random access operator - [] : Gets an element at a given index.

        2. at(index) :  Gets the elements at the given index.

        3. front() : Gets the element at the beginning.

        4. back() : Gets the element at the end of the vector.




D. Some utility functions of vector:

  1. size() : returns the number of elements present in the vector.

    2. empty() : return the boolean value if the vector is empty or not.





This is the end of today's article about the functions of vector. Hope you enjoyed at learnt something from it.


                                        Copyright - Arnab Bhattacharyya














Comments