-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircularqueue.c
113 lines (105 loc) · 1.52 KB
/
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define SIZE 5
int queue[SIZE],data;
int f=-1,r=-1;
void delete();
void display();
void insert();
void main()
{
int ch;
printf("important facts :: int type data should be inserted\n");
while(1)
{
printf("\n1.insert\t2. delete\t3.display\t4. exit\n choice::");
scanf("%d",&ch);
switch(ch)
{
case 1: insert();
break;
case 2: delete();
break;
case 3: display();
break;
case 4: exit(0);
default:
printf("wrong choice ..try again::");
scanf("%d",&ch);
}
}
}
void insert()
{
if((f==0&&r==SIZE-1)||(f==r+1))
{
printf("\nthe queue is full");
return;
}
printf("enter int data ::");
scanf("%d",&data);
if(r==-1)
{
f=0;
r=0;
}
else
if(r==SIZE-1)
{
r=0;
}
else
r=r+1;
queue[r]=data;
printf("%d is inserted",data);
}
void delete()
{
if(f==-1)
{
printf("queue is empty");
return;
}
data=queue[f];
if(f==r)
{
f=-1;
r=-1;
}
else if(f==SIZE-1)
{
f=0;
}
else
{
f=f+1;
}
printf("%d is deleted",data);
}
void display()
{int i;
if(r==-1)
{
printf("nothing to display");
return;
}
if(f<r)
{
for(i=r;i>=f;i--)
{
printf("%d\t",queue[i]);
}
}
else
{
for(i=r;i>=0;i--)
{
printf("%d\t",queue[i]);
}
for(i=SIZE-2;i>=f;i--)
{
printf("%d\t",queue[i]);
}
}
}