LEARN

Journey to CP

View on GitHub

VECTOR

what is vector?

How to use vectors?

1.How is a vector defined?

vector is a template which is included in stl

template:

vector<int> v1;
vector<char> v2;
vector<string> v3;

How to use vector in your program: #include<vector>

intiallizing vector to get a structure; intialise the respective data type which you want as

vector<int> v1;
vector<char> v2;
vector<string> v3;

2.functions included in a vector stl?

v.push_back(a) to add element to the vector at end.

v.size()for finding size of v.

v[i] or v.at(i)for acessing element at position i.

“itr” mentioned below is an iterator.iterator is a pointer to element in the structure; vector<int>::iterator itr;

iterator initilzation
itr=v.begin()here it points to starting element of a vector.

v.insert(itr,a)inserts element a at position itr. v.erase(itr)erases the position representing itr or deletes element *itr .

v.erase(itr1,itr2) erases the positions from it1 t0 it2.

WITH USING VECTORS WE CAN IMPLEMENT STACK AND QUEUE FIND HOW??

go to all topics.