vector in C++
#vector in C++
code :
#include<iostream>
#include<vector> // vector header file
#include<algorithm> // This header file contain sort method
using namespace std;
int main()
{
vector <int> v; // Declaration of vector int
v.push_back(10);
v.push_back(30);
v.push_back(20); // To insert element into vector
v.push_back(90);
v.push_back(50);
int size = v.size(); // To get size of Vector
cout<<"Size of Vector : "<<size<<endl;
// sort the element of vector
sort(v.begin(),v.end()); // TO sort we have to pass two parameter
//which are first element and second element
v.pop_back(); // To Delete Elements from Array
v.pop_back();
size = v.size(); // To get size of Vector
cout<<"Size of Vector : "<<size<<endl;
for(int i=0;i<size;i++) // To display elements of vector
{
cout<<"vector "<<i+1<<" : "<<v[i]<<endl;
}
return(0);
}
Comments
Post a Comment