-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue_4.c
78 lines (70 loc) · 1001 Bytes
/
Queue_4.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
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
#include <stdio.h>
#define size 5
int arr[size];
int n;
int front=-1;
int rear=-1;
int isEmpty(){
if (front==rear){
return 1;
}
return 0;
}
int isFull(){
if (rear==size-1){
return 1;
}
return 0;
}
void enqueue(){
if (isFull()){
printf("queue overflow\n");
}
else {
int value;
printf("ENTER THE VALUE \n");
scanf("%d",&value);
rear++;
arr[rear]=value;
}
}
void dequeue(){
if (isEmpty()){
printf("queue underflow\n");
}
else {
front++;
printf("The dequeud element is %d\n",arr[front]);
}
}
void show(){
int i;
for (i=front+1;i<=rear;i++){
printf("%d",arr[i]);
}
printf("\n");
}
void peek(){
printf("%d\n",arr[rear]);
}
int main(){
do {
printf("1.Enqueue\n2.Dequeue\n3.show\n4.peek\n5.Exit\n");
scanf("%d",&n);
switch (n){
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
show();
break;
case 4:
peek();
break;
}
}while (n!=5);
return 0;
}