-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvector_1.cpp
More file actions
59 lines (49 loc) · 1.18 KB
/
vector_1.cpp
File metadata and controls
59 lines (49 loc) · 1.18 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
#include<iostream>
#include<vector>
using namespace std;
int main()
{
system("cls");
vector<int> v;
cout<<"size: "<<v.size()<<endl;
cout<<"capacity: "<<v.capacity()<<endl;
v.push_back(1); //puts element in last place
cout<<"size: "<<v.size()<<endl;
cout<<"capacity: "<<v.capacity()<<endl;
v.push_back(2);
cout<<"size: "<<v.size()<<endl;
cout<<"capacity: "<<v.capacity()<<endl;
v.push_back(3);
cout<<"size: "<<v.size()<<endl; //3
cout<<"capacity: "<<v.capacity()<<endl; //4 why??
v.push_back(4);
v.push_back(5);
cout<<"\nBefore pop: ";
for(int i:v)
{
cout<<i<<" ";
}
v.pop_back();
cout<<"\nAfter pop: ";
for(int i:v)
{
cout<<v[i-1]<<" ";
}
cout<<"\n2nd index element: "<<v.at(2);
cout<<"\nEmpty of not: "<<v.empty();
cout<<"\nFirst element: "<<v.front();
cout<<"\nlast element: "<<v.back();
int n,a;
cout<<"\nEnter number of element: ";
cin>>n;
vector<int> z;
for(int i=0;i<n;i++)
{
cin>>a;
z.push_back(a);
}
for(int i:z)
{
cout<<i<<" ";
}
}