-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.cpp
More file actions
43 lines (30 loc) · 732 Bytes
/
vector.cpp
File metadata and controls
43 lines (30 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> v1={1,2,3,4};
v1.push_back(9);
v1.pop_back();
v1.shrink_to_fit();
cout<<v1.capacity()<<endl;
cout<<v1.size()<<endl;
//insert in array
vector<int> gv = {1,2,3,4};
gv.insert(gv.begin()+2,5);
cout<<gv[0]<<endl;
//Deleting a element
gv.erase(gv.begin());
cout<<gv[0]<<endl;
cout<<"iterating a vector array"<<endl;
for(int i=0;i<gv.size();i++){
cout<<gv[i]<<endl;;
}
gv.insert(gv.begin(),8);
//itertaing using itr
cout<<"Itertaing using itr"<<endl;
for(auto itr = gv.begin();itr != gv.end();++itr)
{
cout<<*itr<<endl;
}
}