-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraylist.c
More file actions
157 lines (152 loc) · 2.36 KB
/
Arraylist.c
File metadata and controls
157 lines (152 loc) · 2.36 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
#include <stdio.h>
#include<stdlib.h>
int i,pos,ele,ch,r,n,max=10;
int ar[10];
void create()
{
printf("\nEnter number of elements to be added : ");
scanf("%d",&n);
if(n>max)
{
printf("\nThe maximum size is 10 !");
}
else {
for(i=0;i<n;i++)
{
printf("\nEnter element :");
scanf("%d",&ar[i]);
}
}
disp();
}
void insert()
{
printf("\nEnter the position to insert: ");
scanf("%d",&pos);
if(pos>=n)
{
printf("\n invalid location");
}
else{
for (i=max-1;i>=pos-1;i--)
{
ar[i+1]=ar[i];
}
printf("\nEnter the element to insert:");
scanf("%d",&ele);
ar[pos-1]=ele;
n++;}
disp();
}
void disp()
{
printf("\nElements are :");
for (i=0;i<=n-1;i++)
{
printf(" %d ",ar[i]);
}
}
void del()
{
printf("\nEnter the position to be deleted: ");
scanf("%d",&pos);
if(pos>=n)
{
printf("\nInvalid location !");
}
else {
for (i=pos+1;i<n;i++)
{
ar[i-1]=ar[i];
}n--;
}
disp();
}
void makeempty()
{
for(i=0;i<max;i++)
{
ar[i]=NULL;
n--;
}
printf("\nAll Elements are Removed");
}
void isempty()
{
if(n==0){
printf("\nThe array is Empty");
}
else { printf("\nThe array is not empty");
}
}
void isfull()
{
if(n==max)
{printf("\nThe array is full");
}
else{printf("\nThe array is not full");
}
}
void findelement()
{
printf("\nEnter the Element to find:");
scanf("%d",&ele);
for(i=0;i<n;i++)
{
if(ar[i]==ele)
{
printf("\nValue is in the %d position",i);
}
}
}
void replace()
{
printf("\nEnter the position to replace :");
scanf("%d",&r);
printf("\nEnter the element to replace :");
scanf("%d",&ele);
ar[r]=ele;
disp();
}
int main()
{
do{
printf("\n\nList operations \n\n 1.Create \n 2.Insert\n 3.Delete\n 4.Make Empty\n 5.Is full\n 6.Is empty\n 7.Find an element\n 8.Replace an element\n 9.Display\n\n");
printf("\n\n Enter your option : ");
scanf("%d",&ch);
switch(ch){
case 1:
create();
break;
case 2:
insert();
break;
case 3:
del();
break;
case 4:
makeempty();
break;
case 5:
isfull();
break;
case 6:
isempty();
break;
case 7:
findelement();
break;
case 8:
replace();
break;
case 9:
disp();
case 10:
exit(1);
default:
printf("Enter only correct value !");
break;
}
}while(ch!=10);
return 0;
}