37.(c++)----->>>>> c++ vector stl basic.
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
using namespace std;
#define pf printf
#define sc scanf
#define ll long long
int main()
{
vector<int>v;
vector<int>::iterator i;
vector<int>::reverse_iterator ri;
// v.assign(5,100);
for(int i=1;i<=10;i++)
{
v.push_back(i);
}
i=v.begin(); /*for doing this we need declare iterator ,which we have did at first after
the declaration vector.
so,we can do many things by using this vector stuff.*/
v.erase(i+4);
v.insert(i+4,20);
sort(v.rbegin(),v.rend());// sort in descending order .
//sort(v.begin(),v.end());// sort in ascending order.
v.erase(unique(v.begin(),v.end()),v.end());// for deleting duplicate elements.which appears
// more than once .
for(i=v.begin() ;i!=v.end();i++)
{
cout<<*i<<" ";
}
cout<<endl;
cout<<*min_element(v.begin(),v.end())<<endl;// to find maximum
for(ri=v.rbegin();ri!=v.rend();ri++) // reverse whole vector .
{
cout<<*ri<<" ";
}
cout<<endl;
cout<<*max_element(v.begin(),v.end())<<endl;//to find minimum
// cout<<endl;
// cout<<v.max_size()<<endl;// to find range of vector
// cout<<v.capacity()<<endl;
return 0;
}
Comments
Post a Comment