-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathqueue.c
60 lines (59 loc) · 1.18 KB
/
queue.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
//arrayImplementation
#include<stdio.h>
#include<stdlib.h>
#define max 10
int isEmpty(int front) {
if(front==-1)
return 1;
else
return 0;
}
int isFull(int rear) {
if(rear==max)
return 1;
else
return 0;
}
void insert(int *ar,int *front,int *rear,int item) {
if(isFull(*rear)){
printf("Overflow\n");
return;
}
if(*front==-1 && *rear==-1) {
// printf("dd");
*front=*front+1;
*rear=*rear+1;
ar[*front]=item;
}
else {
*rear=*rear+1;
ar[*rear]=item;
}
}
void delete(int *front,int *rear) {
if(isEmpty(*front)||(*rear<*front)){
printf("Underflow\n");
return;
}
*front=*front+1;
}
void print(int *arr,int front,int rear) {
for(int i=front;i<=rear;i++)
printf("%d ",arr[i]);
printf("\n");
}
void main() {
int item=0,front=-1,rear=-1,ar[max];
int ch=0;
while(ch!=69) {
scanf("%d",&ch);
if(ch==1){
scanf("%d",&item);
insert(ar,&front,&rear,item);
}
if(ch==2)
delete(&front,&rear);
}
print(ar,front,rear);
printf("%d %d %d\n",front,rear,ar[front]);
}