-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathQueuewithArray.c
67 lines (60 loc) · 1.04 KB
/
QueuewithArray.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>
#define MAX 5
int Q[MAX];
int front=-1;
int rear=-1;
void Enq(int);
int Deq();
int isempty();
int isfull();
main()
{
int choice,data;
while(1)
{
printf("1.Enq 2.Deq \n");
printf("Enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("Enter the data\n");
scanf("%d",&data);
if(isfull())
printf("Queue is full\n");
else
Enq(data);
break;
case 2: if(isempty())
printf("Queue is empty\n");
else
printf("Data dequed is %d\n",Deq());
break;
}
}
}
int isfull()
{
if(rear==MAX-1) // if Q is full
return 1;
return 0; // Q is not full
}
int isempty()
{
if(front==-1) // Q is empty
return 1;
return 0; // Q is not empty
}
void Enq(int d)
{
if(front==-1) // if Q is empty
front++; // making front to point to first inserted data
Q[++rear]=d; // adding data at rear end
}
int Deq()
{
int temp;
temp=Q[front++];// deleting ele from front end
if(front==rear+1) // means all the elements are deleted
front=rear=-1; // reseting
return temp;
}