-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (42 loc) · 1.21 KB
/
main.cpp
File metadata and controls
46 lines (42 loc) · 1.21 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
#include <iostream>
#include "heap.h"
using namespace std;
int main() {
Heap<int, string> heap;
int choice;
while (true) {
cout << "\n--- Min Heap Menu ---\n";
cout << "1. Insert (key, value)\n";
cout << "2. Get Min\n";
cout << "3. Delete Min\n";
cout << "4. Display Heap\n";
cout << "5. Exit\n";
cout << "Enter choice: ";
cin >> choice;
if (choice == 1) {
int k; string v;
cout << "Enter key: "; cin >> k;
cout << "Enter value: "; cin >> v;
heap.insert(k, v);
cout << "Inserted and heapified.\n";
}
else if (choice == 2) {
try {
auto min = heap.getMin();
cout << "Min element: (" << min.first << ", " << min.second << ")\n";
} catch (const exception& e) {
cout << e.what() << "\n";
}
}
else if (choice == 3) {
heap.deleteMin();
cout << "Deleted and heapified.\n";
}
else if (choice == 4) {
heap.displayLevelOrder();
}
else if (choice == 5) break;
else cout << "Invalid choice.\n";
}
return 0;
}