-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCIR.C
99 lines (92 loc) · 1.19 KB
/
CIR.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
#include<stdio.h>
#include<conio.h>
#define size 5
void que(int);
void deque();
void display();
int cq[size],f=-1,r=-1;
void main()
{
int ch,value;
clrscr();
while(1)
{
printf("\nMenu\n1.queue\n2.Deque\n3.Display\n4.Exit\n");
printf("Enter yoyur choise: ");
scanf("%d",&ch);
switch(ch)
{
case 1: printf("Enter the value to be inserted: ");
scanf("%d",&value);
que(value);
break;
case 2: deque();
break;
case 3: display();
break;
case 4: exit(0);
break;
default:
printf("Wrong choise");
}
}
}
void que(int value)
{
if((f==0 && r==size-1) || (f==r+1))
{
printf("\nQueue is full\n");
return;
}
else
{
if(r==size-1 && f!=0)
r=-1;
cq[++r]=value;
printf("\n queqing success\n");
if(f==-1)
f=0;
}
}
void deque()
{
if(f==-1 && r==-1)
{
printf("\nQueue is empty\n");
return;
}
else
{
printf("Deleted element is %d\n",cq[f++]);
if(f==size)
f==0;
if(f-1==r)
f=r=-1;
}
}
void display()
{
if(f==-1)
{
printf("\nQueue is empty\n");
return;
}
else
{
int i=f;
printf("\nQueue element are: ");
if(f<=r)
{
while(i<=r)
printf("%d\n",cq[i++]);
}
else
{
while(i<=size-1)
printf("%d\n",cq[i++]);
i=0;
while(i<=r)
printf("%d",cq[i++]);
}
}
}