forked from ChandanSitlani/Some-basic-Tricks-of-cp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVECTOR-C++ STL
38 lines (29 loc) · 787 Bytes
/
VECTOR-C++ STL
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
// C++ program to illustrate the
// capacity function in vector
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> g1;
for (int i = 1; i <= 5; i++)
g1.push_back(i);
cout << "Size : " << g1.size();
cout << "\nCapacity : " << g1.capacity();
cout << "\nMax_Size : " << g1.max_size();
// resizes the vector size to 4
g1.resize(4);
// prints the vector size after resize()
cout << "\nSize : " << g1.size();
// checks if the vector is empty or not
if (g1.empty() == false)
cout << "\nVector is not empty";
else
cout << "\nVector is empty";
// Shrinks the vector
g1.shrink_to_fit();
cout << "\nVector elements are: ";
for (auto it = g1.begin(); it != g1.end(); it++)
cout << *it << " ";
return 0;
}