-
Notifications
You must be signed in to change notification settings - Fork 13
/
queue1.cpp
96 lines (94 loc) · 1.31 KB
/
queue1.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
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
#define MAX 20
#include<iostream>
#include<stdlib.h>
#include<conio.h>
using namespace std;
struct queue
{
int a[20];
int front,rear;
}q;
void initialize()
{
q.front=-1;
q.rear=-1;
}
void enqueue(int item)
{
if(q.rear== MAX-1)
{
cout<<"queue overflow";
return;
}
else
{
q.rear++;
q.a[q.rear]=item;
}
}
int dequeue()
{
if(q.front==q.rear)
{
cout<<"queue underflow";
return -9999;
}
else
{
q.front++;
return(q.a[q.front]);
}
}
int isfull()
{
if(q.rear== MAX-1)
return 1;
else
return 0;
}
int isempty()
{
if(q.front==q.rear)
return 1;
else
return 0;
}
void display()
{
int i;
for(i=q.front+1;i<=q.rear;i++)
cout<<q.a[i];
}
int main()
{
int choice,num;
do
{
cout<<endl<<"1.enqueue"<<endl<<"2.dequeue"<<endl<<"3.is full"<<endl<<"4.is empty"<<endl<<"5.display"<<endl<<"6.exit";
cout<<endl;
cin>>choice;
switch(choice)
{
case 1:
cout<<"enter the number to be enqueued";
cin>>num;
enqueue(num);
break;
case 2:
num=dequeue();
cout<<"deleted element is"<<num;
break;
case 3:
isfull();
break;
case 4:
isempty();
break;
case 5:
display();
break;
case 6:exit(0);
}
}while(choice>=1 && choice<=6);
getch();
}