-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path42_vector.cpp
40 lines (33 loc) · 1007 Bytes
/
42_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
#include<iostream>
#include<vector>
using namespace std;
template <class T>
void display(vector<T> &v){
cout<<"Displaying vector : ";
for(T n : v){
cout<<n<<" ";
}
cout<<"\n\tSize : "<<v.size();
cout<<endl;
}
int main ()
{
vector<int> vec1;//Zero length integer vector
display(vec1);
vector<char> vec2; // 4 length charactor vector
vec2.push_back('H');//pushback increase the size of vector and add element to it
vec2.push_back('A');
vec2.push_back('R');
vec2.push_back('D');
display(vec2);
cout<<"\tFront element is : "<<vec2.front()<<endl;
cout<<"\tBack element is : "<<vec2.back()<<endl;
// cout<<"\n Maximum : "<<vec2.max_element(vec2.begin(), vec2. end());
vector<char> vec3(vec2);
display(vec3); // 4 length charactor vector from vec2
vector <char> vec4(6,'H');
display(vec4); // Vector of length 6 with all elements 'H'
vec4.clear();
display(vec4); // Empty vector after clear()
return 0;
}