-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.Dequeue
More file actions
54 lines (48 loc) · 1.22 KB
/
Queue.Dequeue
File metadata and controls
54 lines (48 loc) · 1.22 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
#include <stdio.h>
#define MAX 5
int queue[MAX];
int front = -1;
int rear = -1;
void enqueue(int x){
if (rear == MAX-1){
printf("Queue Overflow\n");
}
else {
if (front== 1)
front = 0;
rear++;
queue[rear]= x;
printf("%d enqueued\n" , x);
}
}
void peek() {
if (front == -1 || front > rear) {
printf("Queue Underflow\n");
}
else {
printf("%d dequeued\n" , queue [front]);
front++;
}
}
void display() {
if (front == -1 || front > rear) {
printf("Queue is Empty\n");
}
else {
printf("Queue elements:");
for (int i = front; i <= rear;i++) {
printf("%d , queue [i]");
}
printf("\n");
}
}
int main() {
enqueue(10);
enqueue(20);
enqueue(30);
peek(); // show front elements
display();
peek();
peek(); // front changes after dequeue
return 0;
}