-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircular.c
81 lines (81 loc) · 1.37 KB
/
circular.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
79
80
81
#include<stdio.h>
#include<stdlib.h>
#define MAX 5
int qf(int count)
{
return(count==MAX)? 1:0;
}
int qe(int count)
{
return(count==0)? 1:0;
}
void rear_insert(int num, int q[], int *r, int *count)
{
if(qf(*count))
{
printf("\n queue is overflown\n");
return;
}
*r=(*r+1)%MAX;
q[*r]=num;
*count+=1;
}
void front_delete(int q[], int *f, int *count)
{
if(qe(*count))
{
printf("\n queue is underflown\n");
return;
}
printf("\n the deleted value if %d\n",q[*f]);
*f=(*f+1)%MAX;
*count-=1;
}
void display(int q[], int f, int count)
{
int i,j;
if(qe(count))
{
printf("queue is empty\n");
return;
}
printf("The contents of the queue are:\n");
i=f;
for(j=1;j<=count;j++)
{
printf("%d\n",q[i]);
i=(i+1)%MAX;
}
printf("\n");
}
int main()
{
int choice,num,count,f,r,q[20];
f=0;
r=-1;
count=0;
printf("\n program to insert delete and display elements in a circular queue\n");
for(;;)
{
printf("1.insert\t2.delete\t3.display\t4.exit\n");
printf("enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("enter the number\n");
scanf("%d",&num);
rear_insert(num,q,&r,&count);
break;
case 2: printf("deleted data\n");
front_delete(q,&f,&count);
break;
case 3: printf("display the elemnts\n");
display(q,f,count);
break;
case 4:exit(0);
default: printf("wrong choice\n");
break;
}
}
return 0;
}