-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program_24.CPP
67 lines (66 loc) · 945 Bytes
/
Program_24.CPP
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
/*Queue Implemented As An Array*/
#include<iostream.h>
#include<process.h>
#include<conio.h>
#define max 20
int q[max],f=-1,r=-1;
void insert();
void del();
void display();
void main()
{ clrscr();
int ch;
while(1)
{
cout<<"\n1.INSERT";
cout<<"\n2.DELETE";
cout<<"\n3.DISPLAY";
cout<<"\n4.EXIT";
cout<<"\nEnter your choice : ";
cin>>ch;
switch(ch)
{
case 1 : insert();
break;
case 2 : del();
break;
case 3 : display();
break;
case 4 : exit(0);
default : cout<<"\nInvalid choice ";
}
}
getch();
}
void insert()
{
if(r==max-1)
cout<<"\nOverflow";
else
{
cin>>q[++r];
if(f==-1)
f++;
}
}
void del()
{
if(f==-1)
cout<<"Underflow";
else
cout<<"\nElement deleted : "<<q[f++];
if(f>r)
{
f=-1;
r=-1;
}
}
void display()
{
int i;
if(f==-1)
cout<<"\nQueue is empty";
else
for(i=f;i<=r;i++)
cout<<q[i];
}