forked from Ashish1820020/Hackoberfest
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcircularqueue.c
64 lines (63 loc) · 985 Bytes
/
circularqueue.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
#include<stdio.h>
#include<stdlib.h>
int q[10],f=-1,r=-1,i,size;
int ch;
void insert(){
if((r==size-1 && f==0) ||(f)-(r)==1){
printf("\nqueue is full");
}
else{
if(r==size-1){
r=-1;
}
if(f==-1){
f=0;
}
r++;
printf("\nEnter a value :");
scanf("%d",&q[r]);
}
}
void delete(){
if(f==-1){
printf("\n\nQueue is empty");
}
else{
if(f==r){
q[f]=0;
f=r=-1;
}
else if(f==size-1 && q[0]>0){
q[f]=f=0;
}
else{
q[f]=0;
f++;
}
}
}
void main(){
printf("Enter queue size :");
scanf("%d",&size);
system("clear");
do{
printf("\n\n1.Insert\n2.Deletes\n3.Display\n5.exit");
printf("\n\nEnter your choice :");
scanf("%d",&ch);
if(ch==1){
insert();
}
if(ch==2){
delete();
}
if(ch==3){
for(i=size-1; i>=0; i--){
printf("\n|%d|",q[i]);
if(i==r)
printf("<-rear");
if(i==f)
printf("<-front");
}
}
}while(ch!=5);
}