-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueue.c
More file actions
77 lines (74 loc) · 689 Bytes
/
queue.c
File metadata and controls
77 lines (74 loc) · 689 Bytes
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
#include<stdio.h>
int n;
int arr[1000];
int f=0;
int r=0;
int enque(int val)
{
arr[r]=val;
if(r==n-1)
{
r=0;
}
else
{
r++;
}
}
int deque()
{
int k=arr[f];
if(f==n-1)
f=0;
else
f=f+1;
return k;
}
int size()
{
if(r>f)
{
printf("%d\n", r-f);
}
else
{
printf("%d\n",n-f+r);
}
}
int display()
{
if(r>f)
{
for(int i=f;i<r;i++)
{
printf("%d ",arr[i]);
}
//printf("\n");
}
else
{
for(int i=f;i<n;i++)
{
printf("%d ",arr[i]);
}
for(int i=0;i<r;i++)
{
printf("%d ",arr[i]);
}
}
printf("\n");
}
int main ()
{
n=5;
enque(5);
enque(3);
enque(7);
deque();
deque();
enque(8);
enque(9);
enque(10);
display();
size();
}