-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpriorityQueue.cpp
More file actions
67 lines (55 loc) · 2.12 KB
/
Copy pathpriorityQueue.cpp
File metadata and controls
67 lines (55 loc) · 2.12 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
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
void heapify(int arr[], int n, int i)
{
int largest = i;
int l = 2*i + 1;
int r = 2*i + 2;
if (l < n && arr[l] > arr[largest])
largest = l;
if (r < n && arr[r] > arr[largest])
largest = r;
if (largest != i)
{
swap(arr[i], arr[largest]);
heapify(arr, n, largest);
}
}
void DisplayHeap(priority_queue<int> gq)
{
priority_queue<int> g = gq;
while (!g.empty()) {
cout << '\t' << g.top();
g.pop();
}
cout << '\n';
}
int main()
{
int t,n;
priority_queue<int> pq; vector<int> a;
do{
printf("1. Insert in Queue\n");
printf("2. Delete in Queue\n");
printf("3. Display Queue\n");
printf("4. Heap Sort\n");
printf("5. Exit\n");
scanf("%d",&t);
switch(t){
case 1: printf("Enter Number to Add to Queue\n");
scanf("%d",&n);
pq.push(n);a.push_back(n);
break;
case 2: printf("Ender Number to Delete\n");
scanf("%d",&n);
break;
case 3:
break;
case 4:
break;
}
}while(t!=5);
return 0;
}