Repository navigation
Expand file tree
/
Copy pathSTL_Vector.cpp
More file actions
86 lines (58 loc) · 1.55 KB
/
Copy pathSTL_Vector.cpp
File metadata and controls
86 lines (58 loc) · 1.55 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
75
76
77
78
79
80
81
82
83
84
85
86
#include <bits/stdc++.h>
using namespace std;
int main()
{
vector <int> v;
// functions -> begin(), end(), rbegin(), rend(), cbegin(), cend()
for(int i = 0; i<10; i++)
v.push_back(i);
cout<<"using cout: ";
for(int i = 0; i<10; i++)
cout<<v[i]<<" ";
cout<<endl<<"using printf: ";
for(int i = 0; i<10; i++)
printf("%d ", v[i]);
cout<<endl<<"using pointer: ";
for(auto itr = v.begin(); itr != v.end(); itr++)
{
printf("%d ", *itr);
}
cout<<endl<<"using reverse pointer: ";
for(auto itr = v.rbegin(); itr != v.rend(); itr++)
{
printf("%d ", *itr);
}
cout<<endl<<"using constant begin pointer: ";
for(auto itr = v.cbegin(); itr != v.cend(); itr++)
{
printf("%d ", *itr);
}
cout<<endl<<"using constant reverse begin pointer: ";
for(auto itr = v.crbegin(); itr != v.crend(); itr++)
{
printf("%d ", *itr);
}
//without auto
cout<<endl<<"Size: "<<v.size()<<endl<<"max size: "<<v.max_size()<<endl
<<"capacity: "<<v.capacity()<<endl;
vector <int > vec;
cout<<"cap of vec: "<<vec.capacity()<<endl;
vec.push_back(1);
cout<<"cap of vec: "<<vec.capacity()<<endl;
for(int i = 2; i<= 256; i++)
{
vec.push_back(i);
if(vec.capacity() == i)
{
printf("%d\n", vec.capacity());
}
}
//reversing a vector
for(int i = 0; i< 10/2; i++)
{
swap(v[i], v[10-i-1]);
}
for(int i = 0; i<10; i++)
cout<<v[i]<<" ";
return 0;
}