-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.cpp
More file actions
109 lines (109 loc) · 1.47 KB
/
queue.cpp
File metadata and controls
109 lines (109 loc) · 1.47 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
#define MAX 10
using namespace std;
struct queue
{
int data[MAX];
int front,rear;
};
class Queue
{
struct queue q;
public:
Queue(){q.front=q.rear=-1;}
int isempty();
int isfull();
void enqueue(int);
int delqueue();
void display();
};
int Queue::isempty()
{
return(q.front==q.rear)?1:0;
}
int Queue::isfull()
{
return(q.rear==MAX-1)?1:0;
}
void Queue::enqueue(int x)
{
q.data[++q.rear]=x;
}
int Queue::delqueue()
{
return q.data[++q.front];
}
void Queue::display()
{
int i;
cout<<"\n";
for(i=q.front+1;i<=q.rear;i++)
{
cout<<q.data[i]<<" ";
}
}
int main()
{
Queue obj;
int ch,x;
do
{
cout<<"\nWelcome.\nPlease enter your choice:\n1.Insert Job\n2.Delete Job\n3.Display\n4.Exit ";
cin>>ch;
switch(ch)
{
case 1:
{
if (!obj.isfull())
{
cout<<"\nEnter data: ";
cin>>x;
obj.enqueue(x);
cout<<endl;
}
else
{
cout<<"Queue Overflow\n";
}
break;
}
case 2:
{
if(!obj.isempty())
{
cout<<"\nDeleted Element= "<<obj.delqueue()<<endl;
}
else
{
cout<<"\nQueue Underflow\n";
}
cout<<"\nRemaining Jobs: \n";
obj.display();
break;
}
case 3:
{
if (!obj.isempty())
{
cout<<"\nQueue contains: \n";
obj.display();
}
else
{
cout<<"\nQueue is empty\n";
}
break;
}
case 4:
{
exit(0);
}
default:
{
cout<<"Invalid choice";
}
}
}
while(true);
return 0;
}