-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvectors.cpp
120 lines (87 loc) · 2.41 KB
/
vectors.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// #include <iostream>
// #include <vector> //this is the library for vectors
// using namespace std;
// int main(){
// vector<int> vec; // this vector is empty
// cout << vec[0];
// return 0;
// }
// #include <iostream>
// #include <vector> //this is the library for vectors
// using namespace std;
// int main(){
// vector<int> vec= {1,2,3,4,5}; // this vector is empty
// cout << vec[0] << endl ;
// cout << vec[1] << endl ;
// cout << vec[2] << endl ;
// cout << vec[3] << endl ;
// cout << vec[4] << endl ;
// return 0;
// }
// #include <iostream>
// #include <vector> //this is the library for vectors
// using namespace std;
// int main(){
// vector<int> vec(3,0); // this vector is empty
// cout << vec[0] << endl;
// cout << vec[1] << endl;
// cout << vec[2] << endl;
// return 0;
// }
// #include <iostream>
// #include <vector> //this is the library for vectors
// using namespace std;
// int main(){
// vector<int> vec(3,0); // this vector is empty
// for (int i : vec){
// cout << i << endl;
// }
// return 0;
// }
// #include <iostream>
// #include <vector> //this is the library for vectors
// using namespace std;
// int main()
// {
// vector<char> vec{'a', 'b', 'c', 'd', 'e'}; // this vector is empty
// cout <<"size = " << vec.size() << endl;
// for (char val : vec)
// {
// cout << val << endl;
// }
// return 0;
// }
// #include <iostream>
// #include <vector> //this is the library for vectors
// using namespace std;
// int main(){
// vector<int> vec; // this vector is empty
// vec.push_back(20);
// vec.push_back(25);
// vec.push_back(86);
// vec.push_back(72);
// cout << "after push back size= " << vec.size() << endl;
// // vec.pop_back(); // will dlt 25
// for (int i : vec){
// cout << i << endl;
// }
// cout << vec.front() << " ";
// cout << vec.back() << " ";
// cout << vec.at(1) << " ";
// return 0;
// }
#include <iostream>
#include <vector> //this is the library for vectors
using namespace std;
int main()
{
vector<int> vec; // this vector is empty
vec.push_back(20);
vec.push_back(25);
vec.push_back(86);
vec.push_back(72);
vec.push_back(83);
cout << "the size of the vector is " << vec.size() << endl;
cout << "the capacity of the vector is " << vec.capacity() << endl;
return 0;
}