-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path37_queue.cpp
More file actions
66 lines (64 loc) · 833 Bytes
/
37_queue.cpp
File metadata and controls
66 lines (64 loc) · 833 Bytes
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
#include<iostream>
#include<stdlib.h>
#define size 5
using namespace std;
class queue
{
private:
int i,s[10],top,bottom;
public:
int item;
queue()
{
top=-1;
bottom=0;
}
void push()
{
if(top==size-1)
cout<<"queue full \n";
else
s[++top]=item;
}
void pop()
{
if(bottom>top)
cout<<"queue empty \n";
else
bottom++;
}
void display()
{
if(bottom>top)
cout<<"empty \n";
else
{
for(i=bottom;i<=top;i++)
cout<<s[i]<< endl;
}
}
};
int main()
{
int choice;
queue ob;
for(;;)
{
cout<<"1:push\n2:pop\n3:display \n4:exit"<<endl;
cout<<"Enter choice";
cin>>choice;
switch(choice)
{
case 1: cout<<"enter item to be inserted";
cin>>ob.item;
ob.push();
break;
case 2: ob.pop();
break;
case 3:ob.display();
break;
default:exit(0);
}
}
return 0;
}