-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathVectors
More file actions
58 lines (46 loc) · 1.38 KB
/
Vectors
File metadata and controls
58 lines (46 loc) · 1.38 KB
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
48
49
50
51
52
53
54
55
56
57
// Detailed video explanation: https://youtu.be/0DNDvuHZDiQ
#include <iostream>
#include <vector>
#include <list>
using namespace std;
int main(){
vector<int> v = {1,2,3};
cout << "size = " << v.size() << ", capacity = " << v.capacity() << endl;
cout << v.max_size() << endl;
v.push_back(5);
cout << "size = " << v.size() << ", capacity = " << v.capacity() << endl;
int cap = v.capacity();
for(int i = 0; i < 100; ++i){
v.push_back(i);
if(cap != v.capacity()){
cap = v.capacity();
cout << "capacity = " << cap << endl;
}
}
//cout << v[104] << endl;
//cout << v.at(104) << endl;
cout << "front = " << v.front() << ", back = " << v.back() << endl;
v.insert(v.begin() + 2, -100);
cout << v[2] << endl;
cout << "size = " << v.size() << endl;
v.pop_back();
cout << "size = " << v.size() << endl;
list<int> ll = {-100,-200,-300};
v.insert(v.begin(), ll.begin(), ll.end());
cout << v[0] << ", " << v[1] << ", " << v[2] << endl;
v.pop_back();
//v.erase(v.begin()+1);
v.erase(v.begin()+1, v.begin()+3);
cout << v[0] << ", " << v[1] << ", " << v[2] << endl;
return 0;
}
/*
size(), capacity(), max_size()
=, [], at()
front(), back()
shrink_to_fit()
empty()
begin(), end(), rbegin(), rend()
insert(), erase()
push_back(), pop_back()
*/