DSL10
DSL10
10
DIV :- B
-------------------------------------------------------------------------------------------------------------------------------
PROBLEM STATEMENT:- Read the marks obtained by students of second year in an online
examination of particular subject. Find out maximum and minimum marks obtained in that
subject. Use heap data structure. Analyze the algorithm.
-------------------------------------------------------------------------------------------------------------------------------
#include <iostream>
int j, temp;
temp = a[i];
j = 2 * i;
while (j <= n) {
j = j + 1;
break;
a[j / 2] = a[j];
j = 2 * j;
a[j / 2] = temp;
}
void MinHeapify(int a[], int i, int n) {
int j, temp;
temp = a[i];
j = 2 * i;
while (j <= n) {
j = j + 1;
break;
a[j / 2] = a[j];
j = 2 * j;
a[j / 2] = temp;
int i, temp;
temp = a[i];
a[i] = a[1];
a[1] = temp;
MaxHeapify(a, 1, i - 1);
temp = a[i];
a[i] = a[1];
a[1] = temp;
MinHeapify(a, 1, i - 1);
MaxHeapify(a, i, n);
MinHeapify(a, i, n);
int main() {
int n;
cin >> n;
n++;
int arr[n];
for (int i = 1; i < n; i++) {
cout << "Enter the marks for subject " << i << ": ";
Build_MaxHeap(arr, n - 1);
MaxHeapSort(arr, n - 1);
Build_MinHeap(arr, n - 1);
MinHeapSort(arr, n - 1);
cout << "\n\nMaximum Marks: " << max << "\nMinimum Marks: " << min;
return 0;
OUTPUT :-