-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path46.cpp
59 lines (50 loc) · 1.54 KB
/
46.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
#include<iostream>
#include<algorithm> //for algo functions
#include<vector> // for vector
#include<numeric> //for accumulate
int main()
{
//program to use the sort(), reverse(), min(), max() and accumulate() function
std::vector<int> v = {122,33,25,654,780,12,342};
//printing the vector
std::vector<int>::iterator p = v.begin();
std::cout<<"Vector v : ";
while(p!=v.end())
{
std::cout<<*p<<" ";
p++;
}
std::cout<<std::endl;
//max element of the vector
//*max_element (first_iterator, last_iterator)
std::cout<<"Max element : "<<*max_element(v.begin(),v.end())<<std::endl;
//min element of the vector
//*min_element (first_iterator, last_iterator)
std::cout<<"Min element : "<<*min_element(v.begin(),v.end())<<std::endl;
//sorting the vector
// sort(first_iterator, last_iterator)
sort(v.begin(),v.end());
std::cout<<"Sorted Vector v : ";
p = v.begin();
while(p!=v.end())
{
std::cout<<*p<<" ";
p++;
}
std::cout<<std::endl;
//reversing the vector
// reverse(first_iterator, last_iterator)
reverse(v.begin(),v.end());
std::cout<<"Reversed Vector v : ";
p = v.begin();
while(p!=v.end())
{
std::cout<<*p<<" ";
p++;
}
std::cout<<std::endl;
//getting the sum of the vector
// accumulate(first_iterator, last_iterator, initial value of sum)
std::cout<<"Sum of the vector : "<<accumulate(v.begin(),v.end(),0)<<std::endl;
return 0;
}