-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exp5.c
52 lines (51 loc) · 944 Bytes
/
Exp5.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
#include<stdio.h>
#define MAX 3
int queue[MAX];
int front = -1, rear = -1;
void enqueue(int val)
{
if(front==-1 && rear==-1){
front = rear = 0;
queue[rear] = val;
}
else if(((rear+1)%MAX)==front){
printf("\nQueue is full!");
}
else{
rear = (rear+1)%MAX;
queue[rear] = val;
}
}
void dequeue()
{
if(front==-1 && rear==-1){
printf("\nQueue is empty!");
}
else if(front==rear){
printf("%d", queue[front]);
front = rear = -1;
}
else{
printf("%d", queue[front]);
front = (front+1)%MAX;
}
}
void display()
{
printf("\n");
int i = front;
while(i!=rear){
printf("%d ", queue[i]);
i = (i+1)%MAX;
}
printf("%d", queue[rear]);
}
void main()
{
enqueue(5);
enqueue(4);
enqueue(3);
dequeue();
enqueue(2);
display();
}