Skip to content

Commit b4111a1

Browse files
authored
insertion_vector.cpp
plz add this file.
1 parent 2221d6c commit b4111a1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

C++/insertion_vector.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//inserting an element in array using vector
2+
#include<bits/stdc++.h>
3+
#include<vector>
4+
using namespace std;
5+
int main()
6+
{
7+
vector<int> v;
8+
int i,ie,n,p;
9+
cout<<"size of array"<<endl;
10+
cin>>n;
11+
for(i=0;i<n;i++)
12+
{
13+
v.push_back(i);
14+
}
15+
for(i=0;i<n;i++)
16+
{
17+
cout<<v[i]<<" ";
18+
}
19+
cout<<"enter which no element you want to insert"<<endl;
20+
cin>>ie;
21+
cout<<"enter index where you want to enter the element"<<endl;
22+
cin>>p;
23+
auto it=v.begin()+p;
24+
auto iter=v.insert(it,ie);
25+
for(i=0;i<n;i++)
26+
{
27+
cout<<v[i]<<" ";
28+
}
29+
}

0 commit comments

Comments
 (0)