-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.c
More file actions
69 lines (69 loc) · 1019 Bytes
/
queue.c
File metadata and controls
69 lines (69 loc) · 1019 Bytes
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
#include<stdio.h>
#include<stdlib.h>
int f=-1,r=-1,q[30],n;
void insert()
{
int x;
if(r>=n-1)
printf("The Queue is full!!\n");
else
{
printf("Enter the element : ");
scanf("%d",&x);
if(r==-1)
f=r=0;
else
r++;
q[r]=x;
}
}
void delete()
{
if(f==-1)
printf("The Queue is empty.\n");
else if(f==r)
f=r=-1;
else
f=f+1;
}
void display()
{
if(f==-1)
printf("The Queue is empty.\n");
else
{
int i = f;
printf("This is the queue\n");
while(i<=r)
{
printf("%d\n",q[i]);
i++;
}
}
}
void main()
{
int ch;
printf("Enter the limit : ");
scanf("%d",&n);
while(ch!=4)
{
printf("Select any of the choices given below :\n");
printf("1. Insert\n2. Delete\n3. Display\n4. Exit\n");
printf("Enter your choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1: insert();
break;
case 2: delete();
break;
case 3: display();
break;
case 4: printf("EXITING.........\n");
break;
default: printf("INVALID ENTRY.\nTRY AGAIN.\n");
break;
}
}
}