-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab6.c
More file actions
83 lines (83 loc) · 1.72 KB
/
Copy pathLab6.c
File metadata and controls
83 lines (83 loc) · 1.72 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
#include <stdio.h>
#define SIZE 4
int rear = -1, front = -1;
char queue[SIZE];
char item;
void insert()
{
if (front == ((rear + 1) % SIZE))
printf("Queue is full.\n");
else
{
rear = (rear + 1) % SIZE;
printf("Enter ITEM: ");
scanf("%*c%c", &item);
queue[rear] = item;
printf("Item inserted: %c\n", item);
if (front == -1) /* first element insertion into queue used for deletion */
front++;
}
}
void del()
{
if (front == -1)
printf("Queue is empty.\n");
else
{
item = queue[front];
printf("ITEM deleted: %c\n", item);
if (front == rear)
{
front = rear = -1;
}
else
front = (front + 1) % SIZE;
}
}
void display()
{
int i, j;
if (front == -1)
printf("Queue is empty.\n");
else
{
printf("Elements of queue are\n");
i = front;
while (i != rear)
{
printf("%c ", queue[i]);
i = (i + 1) % SIZE;
}
printf("%c ", queue[i]);
printf("\n");
}
}
main()
{
int choice;
while (1)
{
choice = 0; /* to select default option of switch when non-integer */
printf("\nCircular Queue Operations:\n");
printf("1.Insert \n2.Delete \n3.Display \n4.Exit \n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
insert();
break;
case 2:
del();
break;
case 3:
display();
break;
case 4:
return;
default:
printf("Invalid choice.\n");
return;
}
}
}