-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTL_vector.cpp
More file actions
47 lines (33 loc) · 982 Bytes
/
STL_vector.cpp
File metadata and controls
47 lines (33 loc) · 982 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
44
45
46
47
#include<iostream>
#include<vector>
using namespace std;
int main() {
vector<int> v;
vector<int> a(5,1); //it means all element assingn with vlaue 1.
cout<<"print a"<<endl;
for(int i:a) {
cout<<i<<" ";
}cout<<endl;
cout<<"capacity -> "<<v.capacity()<<endl;
v.push_back(1);
cout<<"capacity -> "<<v.capacity()<<endl;
v.push_back(2);
cout<<"capacity -> "<<v.capacity()<<endl;
v.push_back(3);
cout<<"capacity -> "<<v.capacity()<<endl;
cout<<"element at 2nd index is -> "<<v.at(2)<<endl;
cout<<"frist element is -> "<<v.front()<<endl;
cout<<"element at last index is -> "<<v.back()<<endl;
cout<<"before pop "<<endl;
for(int i:v) {
cout<<i<<" ";
}cout<<endl;
v.pop_back();
cout<<"after pop "<<endl;
for(int i:v) {
cout<<i<<" ";
}cout<<endl;
cout<<"size before clear -> "<<v.size()<<endl;
v.clear();
cout<<"size after clear -> "<<v.size()<<endl;
}