#include<iostream>
#include<vector>
using namespace std;
void display(vector<int> &v)
{
for(int i=0;i<v.size();i++)
{
cout<<v[i]<<" ";
}
cout<<"\n";
}
int main()
{
vector<int> v;
cout<<"\n initial size="<<v.size()<<" \n ";
int x;
cout<<"\n enter values ";
for(int i=0;i<5;i++)
{
cin>>x;
v.push_back(x);
}
cout<<"\n\n size after inserting 5 values "<<v.size();
cout<<"\n\n current contents ";
display(v);
v.push_back(2);
cout<<"\n\n size after push_back()= "<<v.size()<<"\n";
cout<<"\n\n now the contents of vector after push_back()";
display(v);
cout<<"\n\n iterator created and inserted element at 3rd position ";
vector<int>::iterator itr1=v.begin();
itr1=itr1+2;
v.insert(itr1,1,6);
cout<<"\n\n contents of vector after insrting ";
display(v);
cout<<"\n\n removing elements 3rd and 4th position";
//v.erase(v.begin()+2,v.begin()+6);
v.erase(v.begin()+2,v.begin()+4);
cout<<"\n\n contents after deletion ";
display(v);
cout<<"\n\n";
return 0;
}
#include<vector>
using namespace std;
void display(vector<int> &v)
{
for(int i=0;i<v.size();i++)
{
cout<<v[i]<<" ";
}
cout<<"\n";
}
int main()
{
vector<int> v;
cout<<"\n initial size="<<v.size()<<" \n ";
int x;
cout<<"\n enter values ";
for(int i=0;i<5;i++)
{
cin>>x;
v.push_back(x);
}
cout<<"\n\n size after inserting 5 values "<<v.size();
cout<<"\n\n current contents ";
display(v);
v.push_back(2);
cout<<"\n\n size after push_back()= "<<v.size()<<"\n";
cout<<"\n\n now the contents of vector after push_back()";
display(v);
cout<<"\n\n iterator created and inserted element at 3rd position ";
vector<int>::iterator itr1=v.begin();
itr1=itr1+2;
v.insert(itr1,1,6);
cout<<"\n\n contents of vector after insrting ";
display(v);
cout<<"\n\n removing elements 3rd and 4th position";
//v.erase(v.begin()+2,v.begin()+6);
v.erase(v.begin()+2,v.begin()+4);
cout<<"\n\n contents after deletion ";
display(v);
cout<<"\n\n";
return 0;
}
This comment has been removed by the author.
ReplyDeleteama bhai tme STL use karelu 6e...
ReplyDeletey
ReplyDeleteit is told to define a class template, but you haven't done that.
ReplyDeleteMGM Resorts Casino to Open Casino In Reno - Dr.MD
ReplyDeleteMGM Resorts 울산광역 출장안마 Casino, which opened its doors to the 전주 출장안마 general public in 제주도 출장마사지 2018, announced that it would 광양 출장샵 open its casino in 통영 출장안마 the city's Fremont