0% found this document useful (0 votes)
7 views5 pages

DSL10

This document outlines a practical assignment where students are required to read and analyze marks obtained in an online examination using heap data structures. It includes C++ code for implementing MaxHeap and MinHeap functions to determine the maximum and minimum marks. The program builds heaps, sorts the data, and outputs the maximum and minimum marks obtained by the students.

Uploaded by

rohitgagare50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

DSL10

This document outlines a practical assignment where students are required to read and analyze marks obtained in an online examination using heap data structures. It includes C++ code for implementing MaxHeap and MinHeap functions to determine the maximum and minimum marks. The program builds heaps, sorts the data, and outputs the maximum and minimum marks obtained by the students.

Uploaded by

rohitgagare50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

PRACTICAL NO.

10

NAME :- KUNDAN DHOKE DATE :-

DIV :- B

ROLL NO. :-20

-------------------------------------------------------------------------------------------------------------------------------

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>

using namespace std;

void MaxHeapify(int a[], int i, int n) {

int j, temp;

temp = a[i];

j = 2 * i;

while (j <= n) {

if (j < n && a[j + 1] > a[j])

j = j + 1;

if (temp > a[j])

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) {

if (j < n && a[j + 1] < a[j])

j = j + 1;

if (temp < a[j])

break;

a[j / 2] = a[j];

j = 2 * j;

a[j / 2] = temp;

void MaxHeapSort(int a[], int n) {

int i, temp;

for (i = n; i >= 2; i--) {

temp = a[i];

a[i] = a[1];

a[1] = temp;

MaxHeapify(a, 1, i - 1);

void MinHeapSort(int a[], int n) {


int i, temp;

for (i = n; i >= 2; i--) {

temp = a[i];

a[i] = a[1];

a[1] = temp;

MinHeapify(a, 1, i - 1);

void Build_MaxHeap(int a[], int n) {

for (int i = n / 2; i >= 1; i--)

MaxHeapify(a, i, n);

void Build_MinHeap(int a[], int n) {

for (int i = n / 2; i >= 1; i--)

MinHeapify(a, i, n);

int main() {

int n;

cout << "\nEnter number of subjects of second year: ";

cin >> n;

n++;

int arr[n];
for (int i = 1; i < n; i++) {

cout << "Enter the marks for subject " << i << ": ";

cin >> arr[i];

Build_MaxHeap(arr, n - 1);

cout << "\nArray after building MaxHeap: ";

for (int i = 1; i < n; i++)

cout << arr[i] << " ";

MaxHeapSort(arr, n - 1);

cout << "\n\nSorted Data (Ascending Order): ";

for (int i = 1; i < n; i++)

cout << arr[i] << " ";

int min = arr[1];

Build_MinHeap(arr, n - 1);

cout << "\n\nArray after building MinHeap: ";

for (int i = 1; i < n; i++)

cout << arr[i] << " ";

MinHeapSort(arr, n - 1);

int max = arr[1];


cout << "\n\nSorted Data (Descending Order): ";

for (int i = 1; i < n; i++)

cout << arr[i] << " ";

cout << "\n\nMaximum Marks: " << max << "\nMinimum Marks: " << min;

return 0;

OUTPUT :-

You might also like