-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path39-priority_queue.cpp
More file actions
76 lines (74 loc) · 1.04 KB
/
39-priority_queue.cpp
File metadata and controls
76 lines (74 loc) · 1.04 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
//priority queue
#include<iostream>
#include<stdlib.h>
#define size 5
using namespace std;
class queue
{
private:
int i,s[10],top,bottom;
public:
int item,j;
queue()
{
top=-1;
bottom=0;
}
void push()
{
if(top==size-1)
cout<<"queue full \n";
else
{
j=top;
while(j>=0&&item<s[j])
{
s[j+1]=s[j];
j--;
}
s[j+1]=item;
top++;
}
}
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;
}