-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathIntroVector.cpp
More file actions
50 lines (42 loc) · 918 Bytes
/
IntroVector.cpp
File metadata and controls
50 lines (42 loc) · 918 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
48
49
50
/*
Vector trong C++:
- size();
* truy cap phan tu:
- at(position);
- front();
- back();
* sua doi vector:
- push_back();
- pop_back();
- insert(position, value);
- clear();
- erase(position); or erase(from, to);
- assign(size, value);
*/
#include <iostream>
#include <vector>
using namespace std;
void showInfo(vector<int> v) {
for (auto i = v.begin(); i != v.end(); i++) {
cout << *i << endl;
}
}
int main() {
vector<int> v1;
v1.push_back(10);
v1.push_back(20);
v1.push_back(80);
v1.push_back(50);
cout << "Size: " << v1.size() << endl;
cout << "First element: " << v1.front() << endl;
cout << "Last element: " << v1.back() << endl;
cout << "element at position 2: " << v1.at(2) << endl;
showInfo(v1);
v1.insert(v1.begin()+2, 666);
cout << "\n===========================\n";
showInfo(v1);
v1.assign(2, 0);
cout << "\n===========================\n";
showInfo(v1);
return 0;
}