-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArray_funcs.c
More file actions
166 lines (72 loc) · 1.66 KB
/
Array_funcs.c
File metadata and controls
166 lines (72 loc) · 1.66 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <stdio.h>
#include <stdlib.h>
int
main ()
{
int*a;
int n = 0, i, j = 0, pos,swap;
printf("enter the elements you want to enter");
scanf("%d",&n);
a=(int*)malloc(n*sizeof(int));
printf("Enter the elements");
for(i=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
}
for (i = 0; i <= n - 1; i++)
{
printf ("The entered values are %d \n", a[i], "\n");
}
//insertion
printf ("Enter the location where you wish to insert an element\n");
scanf ("%d", &pos);
printf ("Enter the value to insert\n");
scanf ("%d", &j);
for (i = n - 1; i >= pos - 1; i--)
a[i + 1] = a[i];
a[pos - 1] = j;
printf ("Resultant array is\n");
for (i = 0; i <= n; i++)
printf ("%d\n", a[i]);
//search
printf ("enter value which you want to serach at which position ");
scanf ("%d", &j);
for (i = 0; i <= n; i++)
{
if (a[i] == j)
{
printf ("the user given %d at position is %d \n", j, i + 1);
}
}
//bubble sort
for (i = 0 ; i < n - 1; i++)
{
for (j = 0 ; j < n - i - 1; j++)
{
if (a[j] > a[j+1]) /* For decreasing order use < */
{
swap = a[j];
a[j] = a[j+1];
a[j+1] = swap;
}
}
}
printf("Sorted list in ascending order:\n");
for (i = 0; i < n; i++)
printf("%d\n", a[i]);
//delete
printf ("Enter the location whwre YOU want wish delete the element \n ");
scanf ("%d", &pos);
for (i = pos - 1; i <= n - 1; i++)
a[i] = a[i + 1];
printf ("resultant array \n");
for (i = 0; i <= n - 1; i++)
printf ("%d \n", a[i]);
//traversing
printf ("Traversing of array");
for (i = 0; i < n; i++)
{
printf ("\n a[%d] = %d", i, a[i]);
}
return 0;
}