-
Notifications
You must be signed in to change notification settings - Fork 0
/
vector.cpp
62 lines (49 loc) · 1.25 KB
/
vector.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
//vector declaration,access,print,delete
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//initialize-1
vector<int> v;
v.push_back(2);
v.push_back(10);
v.push_back(45);
v.push_back(2);
v.push_back(1);
cout<<"Vector size = "<< v.size() << endl;
cout<< v[2] << endl;
cout<< v[0] << endl;
//initialize 2
vector<char> v1(10,'r');
cout<< v1[5] << endl;
for(auto c:v1) cout<< c <<" ";
cout<<endl;
vector<string> v2(10,"mango");
cout<< v2[4] << endl;
for(auto c:v2) cout<< c <<" ";
cout<<endl;
vector<double> v3(5,5.2);
for(auto c:v3) cout<< c << " ";
cout<<endl;
//initialize 3
vector<int> vec = {1,4,7,4,10,12,45,100,234,90};
for(int i=0; i<vec.size(); i++){
cout<< vec[i] << " ";
} cout<< "\n";
for(auto i: vec){
cout<< i << " ";
} cout<<"\n";
vec.push_back(77);
vec.push_back(34);
int p = vec.back(); ///cout<< vec.back()<<"\n";
cout<<"Last element = "<<p <<endl;
vec.pop_back();
cout<< vec.back()<<endl;
for(auto i:vec){
cout<< i << " ";
} cout<< "\n";
return 0;
}