-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultipleQueues.c
More file actions
100 lines (60 loc) · 1.03 KB
/
MultipleQueues.c
File metadata and controls
100 lines (60 loc) · 1.03 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include<stdio.h>
#include<stdlib.h>
#define MAX 10
#define n 2
int arr[30];
int front[n];
int rear[n];
int queueSize = MAX/n;
void init(){
for(int i=0;i<n;i++){
front[i] = rear[i] = (i*queueSize);
}
}
void enqueue(int x,int q){
if(rear[q] == (q+1)*queueSize){
printf("queue %d overflow",q);
return;
}
arr[rear[q]] = x;
rear[q]++;
}
int dequeue(int q){
if(front[q] > rear[q]){
printf("Queue %d underflow",q);
return -1;
}
int val = arr[front[q]];
front[q]++;
return val;
}
void display(int q){
for(int i=front[q];i<rear[q];i++){
printf("%d ",arr[i]);
}
}
void displayAll(){
for(int i=0;i<MAX;i++){
printf("%d ",arr[i]);
}
}
int main(){
init();
// enqueue(1,0);
// enqueue(7,0);
// enqueue(9,0);
// enqueue(10,0);
// enqueue(11,0);
enqueue(43,1);
enqueue(4,1);
enqueue(17,1);
enqueue(2,1);
enqueue(16,1);
enqueue(17,1);
// dequeue(0);
// dequeue(0);
// dequeue(1);
// dequeue(1);
// dequeue(1);
// display(1);
}