-
Notifications
You must be signed in to change notification settings - Fork 1
/
13_queue_array.c
66 lines (64 loc) · 1.12 KB
/
13_queue_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
#include<stdio.h>
struct Queue {
int a[100];
int maxsize;
int front,rear;
}queue;
struct Queue create(int maxsize)
{
struct Queue s;
s.maxsize=maxsize;
s.front=0;
s.rear =-1;
return s;
}
void enqueue(int n){
if(queue.rear == queue.maxsize)
printf(" Queue Overflow \n");
else{
(queue.rear)++;
queue.a[queue.rear]=n;
}
}
void dequeue(){
if(queue.rear<queue.front)
printf(" Queue Underflow\n");
else{
printf(" Element %d Popped \n",queue.a[queue.front]);
(queue.front)++;
}
}
void display(){
int i;
if(queue.rear<queue.front)
printf(" Empty Queue\n");
else
for(i=queue.front;i<=queue.rear;i++)
printf("%d ",queue.a[i]);
printf("\n");
}
int main(){
queue=create(10);
int o;
while(1){
printf(" Enter Option\n\t1. Enqueue\n\t2. Front\n\t3. Dequeue\n\t4. Exit \n ");
scanf("%d",&o);
if(o==1){
printf(" enter element : ");
int temp;
scanf("%d",&temp);
enqueue(temp);
}
else if(o==2){
display();
if(queue.front!=-1)
printf(" Front element : %d \n ",queue.a[queue.front]);
else printf(" Empty Queue!\n");
}
else if (o==3){
dequeue();
}
else
break;
}
}