forked from thisisshub/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircular_Queue
74 lines (59 loc) · 1.32 KB
/
Circular_Queue
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
//srishti1302
#include<stdio.h>
#define MAX 6
typedef struct{
int key;
}element;
element cqueue[MAX];
void addcq(int front, int *rear, element item){
if(front==((*rear+1)%MAX))
{
printf("Queue is full OVERFLOW \n ");
return ;
}
*rear=(*rear+1)%MAX;
cqueue[*rear]=item;
}
void deletecq(int *front, int rear){
if(*front==rear)
{
printf("QUEUE IS EMPTY . UNDERFLOW");
return;
}
*front=(*front+1)%MAX;
printf("Deleted element is %d",cqueue[*front].key);
}
void display(int front,int rear){
int i;
if(front==rear)
{
printf("Empty Queue\n");
return;
}
for(i=(front+1)%MAX;i!=(rear+1)%MAX;i=(i+1)%MAX)
printf("%d\t",cqueue[i].key);
}
int main(){
int f=0,r=0,s;
char c='y';
int t;
element item;
while(c=='y'||c=='Y')
{
printf("Enter choice 1.Insert 2.Delete 3.Display ");
scanf("%d",&s);
switch(s)
{
case 1:
printf("\n Enter element to be inserted ");
scanf("%d",&item.key);
addcq(f,&r,item);
break;
case 2: deletecq(&f,r);
break;
case 3: display(f,r);
}
printf("Want to continue y/n ");
scanf(" %c",&c);
}
}