forked from iamAnki/Codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircularqueue.cpp
More file actions
115 lines (108 loc) · 1.91 KB
/
circularqueue.cpp
File metadata and controls
115 lines (108 loc) · 1.91 KB
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
114
#include<stdio.h>
#include<stdlib.h>
#define max 5
int arr[5],f=-1,r=-1,v;
int insert(int v,int arr[5]);
int delete(int arr[max]);
int main()
{
int option;
while(1)
{
printf("insert=1\n");
printf("delete=2\n");
printf("exit=3\n");
printf("enter option\n");
scanf("%d",&option);
switch(option)
{
case 1:
printf("insert operation\n");
printf("enter the value want to insert\n");
scanf("%d",&v);
insert(v,arr);
break;
case 2:
printf("delete operation\n");
delete_q(arr);
break;
case 3:
exit(0);
}
}
return 0;
}
int insert(int v,int arr[5])
{
if((f==0&&r==max-1)||(f==r+1))
{
printf("queue is full");
}
else if(f==-1&&r==-1)
{
f=0;
r=0;
arr[r]=v;
}
else if(r==max-1&&f!=0)
{
r=0;
arr[r]=v;
}
else
{
r++;
arr[r]=v;
}
printf("the queue is \n");
int i;
if(r>=f)
{
for(i=f;i<=r;i++)
printf("%d",arr[i]);
}
else
{
for(i=f;i<=max-1;i++)
printf("%d",arr[i]);
for(i=0;i<=r;i++)
printf("%d",arr[i]);
}
return 0;
}
int delete_queue(int arr[max])
{
int i;
int temp;
if(f==-1 && r==-1 )
printf("queue is empty\n");
else if(f==r)
{
temp=arr[f];
f=r=-1;
}
else if(f==max-1)
{
temp=arr[f];
front=0;
}
else
{
temp=arr[f];
f++;
}
int i;
if(r>=f)
{
for(i=f;i<=r;i++)
printf("%d",arr[i]);
}
else
{
for(i=f;i<=max-1;i++)
printf("%d",arr[i]);
for(i=0;i<=r;i++)
printf("%d",arr[i]);
}
return 0;
}