-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathqueue to store odd even number
117 lines (115 loc) · 2.21 KB
/
queue to store odd even number
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
#include <stdio.h>
int r1=-1,f1=-1,r2=-1,f2=-1,m1=5,m2=5;
int arrs1[5],arrs2[5];
void I1(int i);
void I2(int i);
void del();
void d1();
void d2();
int main() {
int data,c;
while(1){
printf("1=ENQUEUE\n");
printf("2=INSERT\n");
printf("3=DELETE\n");
printf("4=DISPLAY\n");
printf("5=EXIT\n");
printf("Choose option");
scanf("%d",&c);
switch (c) {
case 1:{
printf("Enter data:");
scanf("%d",&data);
if(data%2==0){
I1(data);
}
else
I2(data);
continue;
}
case 2:{
printf("Enter data:");
scanf("%d",&data);
if(data%2==0){
if(r1!=4){
I1(data);
}
else
I2(data);
}
continue;
}
case 3:{
del();
}
case 4: {
printf("Even number:\n");
d1();
printf("\n");
printf("Odd num\n");
d2();
continue;
}
case 5:
return 0;
}
}
}
void I1(int i){
if (r1 == m1 - 1)
printf("Queue Overflow \n");
else
{
if (f1 == - 1)
f1 = 0;
r1 = r1 + 1;
arrs1[r1] = i;
}
}
void I2(int i){
if (r2 == m2 - 1)
printf("Queue Overflow \n");
else
{
if (f2 == - 1)
f2 = 0;
r2 = r2 + 1;
arrs2[r2] = i;
}
}
void d1()
{
int i;
if (f1 == - 1)
printf("Queue is empty \n");
else
{
printf("\n");
for (i = f1; i <= r1; i++)
printf("%d ", arrs1[i]);
printf("\n");
}
}
void d2()
{
int i;
if (f2 == - 1)
printf("Queue is empty \n");
else
{
printf("\n");
for ( i= f2; i <= r2; i++)
printf("%d ", arrs2[i]);
printf("\n");
}
}
void del(){
if(r1>r1){
f1++;
++r2;
}
else {
f2++;
++r1;
}
}