-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayOperations.cpp
56 lines (47 loc) · 1.06 KB
/
ArrayOperations.cpp
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
#include<iostream>
using namespace std ;
int displayMyArray(int arr[] , int usedSize)
{
for (int i =0 ;i <usedSize ; i++)
{
cout<<arr[i]<<"||";
}
return 0;
}
int insertInMyArray(int arr[] , int element , int position , int usedSize)
{
for(int i = usedSize; i>0 ; i--)
{ if ( i == position)
{ arr[i+1] = arr[i];
arr[i] = element;
break;
}
arr[i+1] = arr[i];
}
return 0;
}
int deleteInMyArray(int arr[] , int element , int position , int usedSize)
{
for (int i = position; i < usedSize ; i ++)
{
arr[i] = arr [i+1];
}
return 0;
}
int main()
{
int arr[50];
int usedSize,totalSize,element = 56 , position = 2;
totalSize = 50 ;
usedSize = 5 ;
for (int i = 0 ; i<usedSize ;i++)
arr[i] = i ;
insertInMyArray(arr,element,position,usedSize);
displayMyArray(arr,usedSize+1);
usedSize++ ;
cout<<endl;
deleteInMyArray(arr,element,position,usedSize);
usedSize--;
displayMyArray(arr,usedSize);
return 0 ;
}