-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_insert_delete.cpp
More file actions
59 lines (47 loc) · 991 Bytes
/
array_insert_delete.cpp
File metadata and controls
59 lines (47 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<iostream>
using namespace std;
int main()
{
int a[20],i,value,size,pos;
cout<<"enter the size of an array : "<<endl;
cin>>size;
cout<<"enter the elements of an array : "<<endl;
for(i=0;i<size;i++)
{
cin>>a[i];
}
//insertion
cout<<"enter the value to be inserted : ";
cin>>value;
cout<<"enter the position : ";
cin>>pos;
for(i=size-1;i>=pos;i--)
{
a[i+1]=a[i];
}
a[pos]=value;
size++;
cout<<"after insertion array is :"<<endl;
for(i=0;i<size;i++)
{
cout<< " "<<a[i];
}
cout<<endl;
cout<<endl;
//deletion
cout<<"enter the position whose value is to be deleted :" ;
cin>>pos;
i=pos;
while(i<size)
{
a[i]=a[i+1];
i++;
}
size--;
cout<<"after deletion array is :"<<endl;
for(i=0;i<size;i++)
{
cout<< " "<<a[i];
}
return 0;
}