Vectors in C++
->Watch this for FUN - Funny job interview
Are you getting bored with online lectures?
->Watch this - When online lectures are boring
Vectors in C++ are a sequence container class that implements the dynamic size of the array to store things without caring for its size.
******
Array vs Vectors
An array although is a static allocation where size is fixed, but in Vectors, the size is not fixed due to its dynamic nature.
*****
Declaration of Vectors
std:: vector<int> vec; //under #include<vector> library
*****
Important functions of vectors are:
emplace()->vec.emplace(position,value) inserts the value at the specified position.
emplace_back()->vec.emplace_back(value) inserts the value at the end of the vector.
insert()->vec.insert(position,value) inserts the value at the front of the position given in the function.
resize()->vec.resize(value), resizes the vector's size to the value.
reserve()->vec.reserve(value) reserves the capacity of the vector to be that of value.
size()->vec.size() returns the size of the vector.
capacity()->vec.capacity() returns the overall capacity of the vector. Capacity is always greater than size.
length()->vec.length() returns the length of the vector.
swap()->vec.swap(another vector), swaps vec with any other vector of same type.
push_back()->vec.push_back(value) pushes the value into the vector at last position.
pop_back()->vec.pop_back() pops out the last value in the vector.
front()->vec.front() returns the first value stored in the vector.
back()->vec.back() returns the last value stored in the vector.
clear()->vec.clear() clears the whole vector and make it NULL.
empty()->vec.empty() will check whether the vec is empty(returns true or 1) or not(returns false or 0).
at()->Use as vec.at(i) // Value in vector at index i.
begin()->Use it as vec.begin() // Beginning of the vector.
end()->Use it as vec.end() // End of the vector.
Watch this for FUN - Funny job interview
Are you getting bored with online lectures?
Watch this - When online lectures are boring
Comments
Post a Comment