Dasl 10 P
Dasl 10 P
Roll No:01
Assignment No:10
INPUT:
#include <iostream>
#include <vector>
using namespace std;
public:
// Function to insert a value into the heap
void insert(int value) {
heap.push_back(value);
heapifyUp(heap.size() - 1);
}
public:
// Function to insert a value into the heap
void insert(int value) {
heap.push_back(value);
heapifyUp(heap.size() - 1);
}
do {
cout << "\nMenu:\n";
cout << "1. Add a Single Mark\n";
cout << "2. Add Multiple Marks\n"; // New menu option
cout << "3. Find Maximum Marks\n";
cout << "4. Find Minimum Marks\n";
cout << "5. Display Marks Level-wise\n";
cout << "6. Exit\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
cout << "Enter mark to add: ";
cin >> mark;
minHeap.insert(mark);
maxHeap.insert(mark);
break;
case 2:
cout << "Enter the number of marks to add: ";
cin >> numMarks;
cout << "Enter the marks: ";
for (int i = 0; i < numMarks; ++i) {
cin >> mark;
minHeap.insert(mark);
maxHeap.insert(mark);
}
break;
case 3:
cout << "Maximum Marks: " << maxHeap.getMax() << endl;
break;
case 4:
cout << "Minimum Marks: " << minHeap.getMin() << endl;
break;
case 5:
cout << "Min-Heap ";
minHeap.displayLevelwise();
cout << "Max-Heap ";
maxHeap.displayLevelwise();
break;
case 6:
cout << "Exiting...\n";
break;
default:
cout << "Invalid choice! Try again.\n";
}
} while (choice != 6);
return 0;
}
Output:
Menu:
1. Add a Single Mark
2. Add Multiple Marks
3. Find Maximum Marks
4. Find Minimum Marks
5. Display Marks Level-wise
6. Exit
Enter your choice: 2
Enter the number of marks to add: 5
Enter the marks: 45
12
67
88
29
Menu:
1. Add a Single Mark
2. Add Multiple Marks
3. Find Maximum Marks
4. Find Minimum Marks
5. Display Marks Level-wise
6. Exit
Enter your choice: 3
Maximum Marks: 88
Menu:
1. Add a Single Mark
2. Add Multiple Marks
3. Find Maximum Marks
4. Find Minimum Marks
5. Display Marks Level-wise
6. Exit
Enter your choice: 4
Minimum Marks: 12
Menu:
1. Add a Single Mark
2. Add Multiple Marks
3. Find Maximum Marks
4. Find Minimum Marks
5. Display Marks Level-wise
6. Exit
Enter your choice: 5
Min-Heap Heap as a Binary Tree:
12
29 67
88 45
Max-Heap Heap as a Binary Tree:
88
67 45
12 29
Menu:
1. Add a Single Mark
2. Add Multiple Marks
3. Find Maximum Marks
4. Find Minimum Marks
5. Display Marks Level-wise
6. Exit
Enter your choice: 6
Exiting...