-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinearqueue.cpp
More file actions
126 lines (88 loc) · 1.51 KB
/
Copy pathlinearqueue.cpp
File metadata and controls
126 lines (88 loc) · 1.51 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include<iostream>
using namespace std;
#define max 5
class que{
private:
int f,r;
int m,num;
int q[max];
int val;
public:
que(){
f=-1;
r=-1;
}
void enqueue(){
cout<<"\n Enter the element you want to enter";
cin>>num;
if( r==(max-1)){
cout<<"\n Overflow";
}
else {
r++;
q[r]=num;
if(r==0){
f++;
}
}
}
void isempty(){
if(f==-1&&r==-1){}
cout<<"\n It is empty";
}
void isfull(){
if(r==(max-1)){
cout<<"\n It is full";
}
}
void dequeue(){
if(f==-1||f>r){
cout<<"\n Underflow";
}
else {
val=q[f];
f++;
}
}
void display(){
cout<<"\n The queue is :";
int temp;
if(f==-1&&r==-1){
cout<<"\n Empty";
}
else {
for(temp=f;temp<=r;temp++){
cout<<endl<<q[temp];
}
}
}
};
int main(){
que que1;
int i,choice;
do{
cout<<"\n Enter your choice"<<endl<<"1 - enqueue"<<endl<<"2 - to check empty"<<endl<<"3 - to check full"<<endl<<"4 - dequeue"<<endl<<"5 - display";
cin>>i;
switch(i)
{
case 1:
que1.enqueue();
break;
case 2:
que1.isempty();
break;
case 3:
que1.isfull();
break;
case 4:
que1.dequeue();
break;
case 5:
que1.display();
default:
cout<<"\n Enter a valid option";
}
cout<<"\n Enter 1 to continue";
cin>>choice;
}while(choice==1);
}