-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab6.c
More file actions
80 lines (80 loc) · 1.54 KB
/
Copy pathlab6.c
File metadata and controls
80 lines (80 loc) · 1.54 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
#include <stdio.h>
#include <stdlib.h>
#define QUE_SIZE 5
char item;
int count, q[QUE_SIZE], front, rear;
void insertQ()
{
if (count == QUE_SIZE)
{
printf("Queue Overflow\n");
return;
}
rear = (rear + 1) % QUE_SIZE;
q[rear] = item;
count++;
}
char deleteQ()
{
if (count == 0)
return -1;
int item = q[front];
front = (front + 1) % QUE_SIZE;
count--;
return item;
}
void display()
{
if (count == 0)
{
printf("Queue is empty\n");
return;
}
printf("Contents of the queue are:\n");
int i, f;
for (i = 0, f = front; i < count; i++)
{
printf("%c\n", q[f]);
f = (f + 1) % QUE_SIZE;
}
}
int main()
{
int choice;
front = 0;
rear = -1;
for (;;)
{
printf("1.Insert\t 2.Delete\n");
printf("3.Display\t 4.Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("Enter the item to be inserted: ");
scanf(" %c", &item);
insertQ();
break;
case 2:
item = deleteQ();
if (item == -1)
{
printf("Queue is empty\n");
}
else
{
printf("Item deleted from queue is %c\n", item);
}
break;
case 3:
display();
break;
case 4:
exit(0);
default:
printf("Invalid choice\n");
}
}
return 0;
}