-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.cpp
More file actions
74 lines (62 loc) · 1.51 KB
/
vector.cpp
File metadata and controls
74 lines (62 loc) · 1.51 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
author: Alessandro Ferrante
* vector.cpp
*/
/*
| The file introduces the standard <vector> class
| with some of its methods for performing operations with vectors
*/
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char ** argv) {
// ? Create a vector v with 3 elements of value 0
vector<float> v;
// ? Create a vector v1 by allocating the elements of v
vector<float> v1;//(v.get_allocator());
//? add the elements to the end of the vector
v.push_back(10.3);
v.push_back(5.2);
v.push_back(4.1);
v.push_back(1.4);
//? deletes the elements at the end of the vector
v.pop_back();
// ? to view v
cout << "Vector v : " ;
for(const auto& p : v) {
cout << p << " -> ";
}
cout << "END" << endl;
// ? to view v1
cout << "Vector v1 : ";
if( v1.empty( ) ){
cout << "empty vector!" << endl;
}
else{
for(const auto& d : v1) {
cout << d << " -> ";
}
cout << "END" << endl;
}
// ? inverts the elements of the vectors
cout << "Swap" << endl;
v.swap(v1);
// ? to view v
cout << "Vector v : ";
if( v.empty( ) ){
cout << "empty vector!" << endl;
}
else{
for(const auto& p : v) {
cout << p << " -> ";
}
cout << "END" << endl;
}
// ? to view v1
cout << "Vector v1 : " ;
for(const auto& d : v1) {
cout << d << " -> ";
}
cout << "END" << endl;
return 0;
}