forked from tarunsinghofficial/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircularqueueusingarray.c
90 lines (86 loc) · 1.36 KB
/
circularqueueusingarray.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
/* SOMASHRI RASTOGI */
#include<stdio.h>
#include<conio.h>
# define MAX 6
int CQ[MAX], front = 0,rear = 0,count = 0;
void insertCQ()
{
int data;
if(count == MAX)
{
printf("Circular queue is full");
}
else
{
printf("\n Enter data: ");
scanf("%d", &data);
CQ[rear] = data;
rear = (rear + 1) % MAX;
count ++;
printf("\n Data Inserted in the Circular Queue ");
}
}
void deleteCQ()
{
if(count == 0)
{
printf("\n\nCircular Queue is Empty");
}
else
{
printf("\n Deleted element from Circular Queue is %d ", CQ[front]);
front = (front + 1) % MAX;
count --;
}
}
void display()
{
int i, j;
if(count == 0)
{
printf("\n\n\t Circular Queue is Empty");
}
else
{
printf("\n Elements in Circular Queue are: ");
j = count;
for(i = front; j != 0; j--)
{
printf("%d\t", CQ[i]);
i = (i + 1) % MAX;
}
}
}
int menu()
{
int ch;
printf("\n \t Circular Queue Operations using ARRAY..");
printf("\n 1. Insertion ");
printf("\n 2. Deletion ");
printf("\n 3. Display the Queue");
printf("\n 4. Quit ");
printf("\n Enter Your Choice: ");
scanf("%d", &ch);
return ch;
}
void main()
{
int ch;
do
{
ch = menu();
switch(ch)
{
case 1: insertCQ();
break;
case 2: deleteCQ();
break;
case 3: display();
break;
case 4: return;
default: printf("Invalid choice");
}
getch();
}
while(1);
}