-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircular_queue.c
71 lines (64 loc) · 1.23 KB
/
circular_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
61
62
63
64
65
66
67
68
69
70
71
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 5
int front=0,rear=-1,count=0;
int q[MAX],ele,choice,i;
void insert()
{
if(count == MAX)
{
printf("Queue is overflow\n");
return;
}
printf("enter the element to insert:");
scanf("%d",&ele);
rear = (rear+1)%MAX;
q[rear]=ele;
count++;
}
void delete()
{
if(count == 0)
{
printf("Queue is underflow\n");
return;
}
printf("Element deleted is:%d\n",q[front]);
front=(front+1)%MAX;
count--;
}
void display()
{
if(count == 0)
{
printf("Queue is underflow\n");
return;
}
printf("Queue elements are:\n");
for(i=front; i != rear; i=(i+1)%MAX)
{
printf("%d\t",q[i]);
}
printf("%d\n",q[i]);
}
void main()
{
while(1)
{
printf("enter your choice\n1.Insert\n2.Delete\n3.Display\n4.exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1:insert();
break;
case 2:delete();
break;
case 3:display();
break;
case 4:exit(0);
break;
default:printf("invalid choice\n");
}
}
}