vector_important_functions.cpp File Reference

A C++ program to demonstrate working of std::sort(), std::reverse() More...

`#include <algorithm>`
`#include <iostream>`
`#include <numeric>`
`#include <vector>`
Include dependency graph for vector_important_functions.cpp:

## Functions

int | main ()

## Detailed Description

A C++ program to demonstrate working of std::sort(), std::reverse()

## Function Documentation

## main()

int main | ( | void |  | ) |

Main function

{
// Initializing vector with array values
int arr[] = {10, 20, 5, 23, 42, 15};
int n = sizeof(arr) / sizeof(arr[0]);
std::vector<int> vect(arr, arr + n);
std::cout << "Vector is: ";
for (int i = 0; i < n; i++) std::cout << vect[i] << " ";
// Sorting the Vector in Ascending order
std::sort(vect.begin(), vect.end());
std::cout << "\nVector after sorting is: ";
for (int i = 0; i < n; i++) std::cout << vect[i] << " ";
// Reversing the Vector
std::reverse(vect.begin(), vect.end());
std::cout << "\nVector after reversing is: ";
for (int i = 0; i < 6; i++) std::cout << vect[i] << " ";
std::cout << "\nMaximum element of vector is: ";
std::cout << *max_element(vect.begin(), vect.end());
std::cout << "\nMinimum element of vector is: ";
std::cout << *min_element(vect.begin(), vect.end());
// Starting the summation from 0
std::cout << "\nThe summation of vector elements is: ";
std::cout << accumulate(vect.begin(), vect.end(), 0);
return 0;
}
std::accumulate
T accumulate(T... args)
std::cout
std::max_element
T max_element(T... args)
std::min_element
T min_element(T... args)
std::reverse
T reverse(T... args)
std::sort
T sort(T... args)
std::vector< int >
Here is the call graph for this function: