-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.cpp
56 lines (53 loc) · 1.09 KB
/
queue.cpp
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
#include<bits/stdc++.h>
using namespace std;
#define q_size 100
int front=0,rear=-1;
void enqeue(int arr[], int value){
if(rear==q_size){
printf("queue overflow\n");
}
else{
arr[++rear]=value;
}
}
int deqeue(int arr[])
{
if(front>rear)
{
printf("queue is empty\n");
return -1;
}
else {
return arr[front++];
}
}
void display(int queue[]){
printf("queue:");
for(int i=front; i<=rear;++i)
printf("%d ",queue[i]);
printf("\n");
}
int main()
{
int arr[q_size];
printf("deqeue=%d\n",deqeue(arr));
enqeue(arr,1);
enqeue(arr,4);
enqeue(arr,3);
enqeue(arr,2);
enqeue(arr,5);
display(arr);
enqeue(arr,56);
display(arr);
printf("deqeue=%d\n",deqeue(arr));
printf("deqeue=%d\n",deqeue(arr));
printf("deqeue=%d\n",deqeue(arr));
printf("deqeue=%d\n",deqeue(arr));
printf("deqeue=%d\n",deqeue(arr));
printf("deqeue=%d\n",deqeue(arr));
printf("deqeue=%d\n",deqeue(arr));
printf("deqeue=%d\n",deqeue(arr));
// for(int i=0;i<q_size;i++)
// for(int i=0;i<q_size;i++)
// printf("%d ",arr[i]);
}