problem on vector sort- click here
Solution :
Vector are sequence containers that can change in size. They represent arrays.
Code :
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
vector<int> v; // this is how a vector is declared
int n;
int size; // inputting the size of the vector array
cin>>size;
int i;
for(i=0;i<size;i++){
cin>>n;
v.push_back(n); // this functions pushes the data in the vector
}
sort(v.begin(), v.end()); // sort function defined in algorithm library
for(i=0;i<size;i++){
cout<<v[i]<<" "; // outputting the vector elements
}
return 0;
}
No comments:
Post a Comment