forked from sbis04/data-structures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcirc queue by array.c
More file actions
108 lines (106 loc) · 1.41 KB
/
circ queue by array.c
File metadata and controls
108 lines (106 loc) · 1.41 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
#include<stdio.h>
int a[10];
int i,n,x,num;
int front=-1,rear=-1;
int main()
{
printf("enter total no of element in array\n");
scanf("%d",&n);
do
{
printf("1:insertion\n");
printf("2:deletion\n");
printf("3:display\n");
printf("4:exit\n");
printf("enter ur choice\n");
scanf("%d",&x);
switch(x)
{
case 1:
insertion();
break;
case 2:
deletion();
break;
case 3:
display();
break;
}
}
while(x<=3);
}
insertion()
{
if((front==0&&rear==n-1)||(front==rear+1))
printf("overflow\n");
else
{
printf("enter the no to be insert\n");
scanf("%d",&num);
if(front==-1&&rear==-1)
{
front=0;
rear=0;
}
else
{
if(front!=0&&rear==n-1)
{
rear=0;
}
else
{
rear=rear+1;
}
}
}
a[rear]=num;
}
deletion()
{
if(front==-1&&rear==-1)
printf("underflow\n");
else
{
if(front==rear)
{
printf("the deleted element is %d\n",a[front]);
front=-1;
rear=-1;
}
else
{
if(front==n-1)
{
printf("the deleted element is %d\n",a[front]);
front=0;
}
else
{
printf("the deleted element is %d\n",a[front]);
front=front+1;
}
}
}
}
display()
{
if(front==-1&&rear==-1)
printf("queue is empty\n");
else
{
printf("the queue is\n");
if(front>rear)
{
for(i=front;i<n;i++)
printf("%d\n",a[i]);
for(i=0;i<=rear;i++)
printf("%d\n",a[i]);
}
else
{
for(i=front;i<=rear;i++)
printf("%d\n",a[i]);
}
}
}