forked from 0xali3n/Hactoberfest-Beginner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.c
75 lines (72 loc) · 1.5 KB
/
Queue.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
#include<stdio.h>
#define MAX 5
struct queue
{
int ar[MAX];
int front,rear;
}s;
void insertion(int n)
{
if(s.rear==MAX-1)printf("QUEUE is full");
else if(s.rear==-1)
{
s.rear=s.front=0;
s.ar[s.rear]=n;
}
else
{
s.rear++;
s.ar[s.rear]=n;
}
}
int deletion()
{ int b;
if(s.front==-1)printf("QUEUE is empty\n");
else if(s.rear==s.front)
{
b=s.ar[s.front];
s.front=s.rear=-1;
}
else
{
b=s.ar[s.front];
s.front++;
}
return b;
}
void display()
{
if(s.rear==-1)printf("QUEUE is empty");
else{
for(int i=s.front;i<=s.rear;i++)printf("%d ",s.ar[i]);
}
}
void main()
{
s.front=s.rear=-1;
int choice,k=1,n;
while(k==1)
{
printf("Press 1 for insertion\nPress 2 for deletion\nPress 3 for display\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the integer to be inserted ");
scanf("%d",&n);
insertion(n);
break;
case 2:
n=deletion();
if(s.rear!=-1)printf("deleted value is: %d",n);
break;
case 3:
display();
break;
default:
printf("Wrong option entered");
}
printf("If you want to continue the procedure press 1\nPress 0 for exit\n");
scanf("%d",&k);
}
}