forked from kallaway/100-days-of-code
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Queue.c
53 lines (53 loc) · 853 Bytes
/
Queue.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
#include <stdio.h>
void enqueue(int queue[],int element,int rear,int size);
void dequeue(int queue[],int front,int rear);
int Front(int queue[],int front);
int size(int queue[],int rear);
int main()
{
int queue[10];
enqueue(queue, 2, 0, 10);
dequeue(queue, 0, 1);
int s=size(queue, 0);
printf("%d\n%d",queue[0],s);
}
void enqueue(int queue[],int element,int rear,int size)
{
if(rear==size)
{
printf("overflow ,full queue\n");
}
else
{
queue[rear]=element;
rear++;
}
}
void dequeue(int queue[],int front,int rear)
{
if(front==rear)
{
printf("underflow,empty\n");
}
else
{
queue[front]=0;
front++;
}
}
int Front(int queue[],int front)
{
return queue[front];
}
int size(int queue[],int rear)
{
int c=0;
for(int i=0;i<rear;i++)
{
if(queue[i])
{
c++;
}
}
return c;
}