This repository has been archived by the owner on Feb 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy path3. DEQUEUE_ARRAY.c
202 lines (178 loc) · 4.56 KB
/
3. DEQUEUE_ARRAY.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include<stdio.h>
#include<stdlib.h>
#include<process.h>
void Input_restricted();
void Output_restricted();
void Insert_front();
void Insert_rear();
void Delete_front();
void Delete_rear();
void Display_Dequeue();
int Dequeue[100],front=-1,rear=-1,size;
int main()
{
int choice;
while(1)
{
printf("\n\nCHOOSE THE TYPE OF DEQUEUE:\n");
printf("\n1 - Input restricted Dequeue.\n2 - Output restricted Dequeue.\n3 - Stop executing.\n");
scanf("%d",&choice);
switch(choice)
{
case 1: Input_restricted();
break;
case 2: Output_restricted();
break;
case 3: exit(0);
break;
default: printf("Wrong Choice!");
break;
}
}
return 0;
}
void Input_restricted()
{
int ch;
printf("Enter the size of Dequeue to be formed: ");
scanf("%d",&size);
while(1)
{
printf("\n\nOPERATIONS ON INPUT RESTRICTED DEQUEUE\n");
printf("\nChoose:\n1 - Insert from end.\n2 - Delete from beginning.\n3 - Delete from end.\n4 - Display the dequeue.\n5 - Stop executing.\n");
scanf("%d",&ch);
switch(ch)
{
case 1: Insert_rear();
break;
case 2: Delete_front();
break;
case 3: Delete_rear();
break;
case 4: Display_Dequeue();
break;
case 5: front=rear=-1;
return;
default: printf("Wrong Choice!");
break;
}
}
}
void Output_restricted()
{
int ch;
printf("Enter the size of Dequeue to be formed: ");
scanf("%d",&size);
while(1)
{
printf("\n\nOPERATIONS ON INPUT RESTRICTED DEQUEUE\n");
printf("\nChoose:\n1 - Insert from beginning.\n2 - Insert from end.\n3 - Delete from beginning.\n4 - Display the dequeue.\n5 - Stop executing.\n");
scanf("%d",&ch);
switch(ch)
{
case 1: Insert_front();
break;
case 2: Insert_rear();
break;
case 3: Delete_front();
break;
case 4: Display_Dequeue();
break;
case 5: front=rear=-1;
return;
default: printf("Wrong Choice!");
break;
}
}
}
void Insert_front()
{
int element,i;
if(front==0 && rear==size-1)
{
printf("\nOVERFLOW!Cannot insert more elements!");
return;
}
else if(front==0)
printf("\nCannot be inserted from the front!\n");
else
{
printf("\nEnter element to be inserted in the Queue: ");
scanf("%d",&element);
if(front==-1)
{ front=0;
rear=0;
printf("\nSince the Queue is empty, the element %d cannot be inserted from the front.",element);
Dequeue[rear]=element;
printf("\nElement %d has been inserted from the rear.\n",element);
}
else
{
front-=1;
Dequeue[front]=element;
printf("\nElement %d has been inserted from the front.\n",element);
}
}
}
void Insert_rear()
{
int element;
{
if(rear==size-1)
{
printf("\nOVERFLOW!Cannot insert more elements!");
return;
}
else
{
printf("\nEnter element to be inserted in the Queue: ");
scanf("%d",&element);
if(front==-1)
{ front=0;
rear=0;
}
else
rear+=1;
Dequeue[rear]=element;
printf("\nElement %d has been inserted from the rear.\n",element);
}
}
}
void Delete_front()
{
if(front==-1)
printf("\nUNDERFLOW! Empty dequeue! No elements found for deletion.\n");
else
{
if(front==rear)
front=rear=-1;
else
front+=1;
printf("\nElement %d has been deleted from the front.\n",Dequeue[front-1]);
}
}
void Delete_rear()
{
if(front==-1)
printf("\nUNDERFLOW! Empty queue! No elements found for deletion.\n");
else
{
if(front==rear)
front=rear=-1;
else
rear-=1;
printf("\nElement %d has been deleted from the rear.\n",Dequeue[rear+1]);
}
}
void Display_Dequeue()
{
int i;
if(front==-1)
printf("Empty queue! No elements found.\n");
else
{
printf("\nNow the Queue is: \n");
for(i=front;i<=rear;i++)
printf("%d ",Dequeue[i]);
}
}