In: Computer Science
In basic C++
Create a function that takes in a vector, sorts it, then outputs to the console the result.
#include <bits/stdc++.h>
using namespace std;
void order(vector<int> v)
{
sort(v.begin(), v.end());
cout << "Elements in increasing order is:\n";
for (int i = 0; i < v.size(); i++)
cout << v[i] << " ";
}
int main()
{
int n, i, p;
cout << "Enter the size of the vector ";
cin >> n;
vector<int> v;
for (i = 0; i < n; i++)
{
cin >> p;
v.push_back(p);
}
order(v);
}
PLEASE LIKE IT RAISE YOUR THUMBS UP
IF YOU ARE HAVING ANY DOUBT FEEL FREE TO ASK IN COMMENT
SECTION