-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayProgramWithAllOperations.c
103 lines (102 loc) · 2.05 KB
/
ArrayProgramWithAllOperations.c
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include<stdio.h>
int traverseArray();
int insertArray();
int deleteArray();
int main()
{
int n;
int arr[100];
printf("----------------------------------------\n");
printf("Enter the no. of elements:");
scanf("%d",&n);
traverseArray(arr,n);
}
int traverseArray(int brr[], int x)
{
int i;
printf("The elements are\n");
for(i=0;i<x;i++)
{
scanf("%d",&brr[i]);
}
printf("----------------------------------------\n");
printf("The unsorted elments entered are\n");
for(i=0;i<x;i++)
{
printf("%d\t",brr[i]);
}
printf("\n----------------------------------------\n");
insertArray(brr,x);
}
int insertArray(int crr[], int p)
{
int i,key,loc;
printf("\nEnter the key element to be inserted:");
scanf("%d",&key);
printf("----------------------------------------\n");
printf("Enter the location at which element to be inserted:");
scanf("%d",&loc);
printf("----------------------------------------\n");
for(i=p-1;i>=loc-1;i--)
{
crr[i+1] = crr[i];
}
crr[loc-1] = key;
p++;
printf("After insertion, the array is\n");
for(i=0;i<p;i++)
{
printf("%d\t",crr[i]);
}
printf("\n----------------------------------------\n");
sortArray(crr,p);
}
int sortArray(int drr[], int k)
{
int i,j,temp = 0,flag = 0;
for(i=0;i<k;i++)
{
for(j=i+1;j<k;j++)
{
if(drr[i] > drr[j])
{
temp = drr[j];
drr[j] = drr[i];
drr[i] = temp;
flag++;
}
}
if(flag == 0)
{
break;
}
}
printf("\nThe sorted array is\n");
for(i=0;i<k;i++)
{
printf("%d\t",drr[i]);
}
printf("\n----------------------------------------\n");
deleteArray(drr,k);
}
int deleteArray(int err[], int q)
{
int i,loc1,temp = 0;
printf("\nEnter the location to delete the element form the array:");
scanf("%d",&loc1);
temp = err[loc1-1];
printf("----------------------------------------\n");
for(i=loc1-1;i<q;i++)
{
err[i] = err[i+1];
}
q--;
printf("After deletion\n");
for(i=0;i<q;i++)
{
printf("%d\t",err[i]);
}
printf("\n----------------------------------------\n");
printf("Element deleted : %d", temp);
}
//it's always a good practice to program daily :)