-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlab6.c
115 lines (113 loc) · 2.12 KB
/
lab6.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define MAX 4
char q[MAX], item;
int f = 0, r = 0, c = 0;
void insert(char data)
{
// printf("Enter the ele: ");
// int flushall(void);
// scanf("%c", &item);
printf("element entered is %c \n", data);
if ((f == 1 && r == MAX) || f == r + 1)
{
printf("queue overflow\n");
return;
}
if (f == 0)
f = r = 1;
else if (r == MAX)
r = 1;
else
r = r + 1;
q[r] = data;
printf("%c is inserted\n", data);
c = c + 1;
return;
}
void delete ()
{
if (f == 0)
{
printf("queue underflow\n");
return;
}
item = q[f];
printf("\nDeleted Element is %c\n", item);
if (f == r)
f = r = 0;
else if (f == MAX)
f = 1;
else
f = f + 1;
c = c - 1;
return;
}
void display()
{
int i;
if (f == 0)
{
printf("queue underflow\n");
return;
}
else //f<r
{
printf("queue elements are\n");
if (f <= r)
{
for (i = f; i <= r; i++)
{
printf("%c\t", q[i]);
}
}
else
{
for (i = f; i <= MAX; i++)
{
printf("%c\t", q[i]);
}
for (i = 1; i <= r; i++)
{
printf("%c\t", q[i]);
}
}
}
printf("\nStatus of Queue:\n rear is at %d\n front is at %d", r, f);
return;
}
int main()
{
int ch;
char data;
// getch();
// clrscr();
printf("Q Operations\n");
printf("1.Insert\n2.Delete\n3.Display\n4.Exit\n");
while (1)
{
printf("Enter your Choice\n");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("Enter the ele: ");
scanf(" %c", &data);
insert(data);
break;
case 2:
delete ();
break;
case 3:
display();
break;
case 4:
exit(1);
break;
default:
printf("Invalid\n");
}
}
return 0;
}