-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueArray.cpp
More file actions
93 lines (63 loc) · 1.03 KB
/
QueueArray.cpp
File metadata and controls
93 lines (63 loc) · 1.03 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
84
85
86
87
88
89
90
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
const int max=1000;
int q[max];
int front=-1,rear=-1;
void insert();
void deletion();
void display();
int main()
{
char c;
while(1)
{
printf("Enter your choice :\n a.Insert \n b.Delete \n c.Display \n d.Exit \n");
scanf(" %c",&c);
switch(c)
{
case 'a' : insert();break;
case 'b' : deletion();break;
case 'c' : display();break;
case 'd' : exit(0);
default : printf("Invalid Input. Try again \n");
}
}
}
void insert()
{
int temp;
if(rear==max-1)
{
printf("The queue is full(Overflow) \n");
return;
}
printf("Enter the value to be inserted \n");
scanf("%d",&temp);
if(front==-1)
front=0;
q[++rear]=temp;
}
void deletion()
{
if(front==-1)
{
printf("List is empty(underflow)\n");
return;
}
printf("The value deleted is : %d \n",q[front]);
front++;
if(front==rear+1)
front=rear=-1;
}
void display()
{
int i;
if(front ==-1)
{
printf("The list is empty\n");
return;
}
for(i=front;i<=rear;i++)
printf("%d \n",q[i]);
}