-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_insertion.cpp
More file actions
67 lines (57 loc) · 1.25 KB
/
Copy patharray_insertion.cpp
File metadata and controls
67 lines (57 loc) · 1.25 KB
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
60
61
62
63
64
65
66
67
#include<iostream>
#include<string.h>
using namespace std;
void display(int arr[], int n)
{
//Traversal
for(int i =0; i<n; i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;
}
int indInsertion(int arr[],int size, int element,int capacity, int position)
{
if(size>=capacity)
return 0;
size++;
for(int i=size-1;i>=position;i--)
{
arr[i+1]=arr[i];
}
arr[position]= element;
return 1;
}
int main()
{
int arr[100]= {2,4,3,5,6,7,8};
int ele,posi,cap=100,size=7,e;
/*char ch = 'y';
while(ch =='y')
{
cout<<"enter value for arr["<<size<<"]=";
cin>>arr[size];
cout<<"y/n to enter more element:";
cin>>ch;
size++;
}
cout<<"enter 1 to display the array:";
cin>>e;
if(e==1)
display(arr,size);*/
cout<<"enter the element to be insert:";
cin>>ele;
cout<<"enter the position:";
cin>>posi;
indInsertion(arr,size,ele,cap,posi);
size+=1;
display(arr,size);
/* if(indInsertion(arr,size,ele,cap,posi))
{
size++;
cout<<"element inserted successfully"<<endl;
display(arr,size);
}
else
cout<<"error";*/
}