0% found this document useful (0 votes)
6 views

Lab 12 V3

Lab12V3

Uploaded by

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

Lab 12 V3

Lab12V3

Uploaded by

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

University of Central Punjab

Faculty of Information Technology

Data Structures and Algorithms


Spring 2024

Lab 13
Topic  Max Heap
 Min Heap
 Heap Sort

The basic purpose of this lab is to implement Max Heap, Min Heap, Heap Sort and
Objective test its Applications

Instructions:
• Indent your code.
• Use meaningful variable names.
• Plan your code carefully on a piece of paper before you implement it.
• Name of the program should be same as the task name. i.e. the first program should be
Task_1.cpp
• void main() is not allowed. Use int main()
• You have to work in multiple files. i.e separate .h and .cpp files
• You are not allowed to use any built-in functions
• You are required to follow the naming conventions as follow:
o Variables: firstName; (no underscores allowed)
o Function: getName(); (no underscores allowed)
o ClassName: BankAccount (no underscores allowed)

Students are required to complete the following tasks in lab timings.


Task 1

Implement a Min Heap using an array and support the insertion operation. Write a function to insert a
new element into the Min Heap while maintaining the heap property.

Requirements:

1. Define a MinHeap class.

Attributes of MinHeap class are

 int *heapArray;
 int capacity;
 int heapSize;
Functions for MinHeap class:

 void Insert(int key)


 void display();
 void heapifyUp(int index);

2. Create constructor, destructor for the MinHeap class


3. Implement above methods
4. Write a main function to demonstrate the usage of the MinHeap class with insertion.

Task 2

Implement a Max Heap using an array and support the insertion operation. Write a function to insert a
new element into the Max Heap while maintaining the heap property.

Requirements:

1. Define a MaxHeap class.

Attributes of MaxHeap class are

 int *heapArray;
 int capacity;
 int heapSize;

Functions for MaxHeap class:

 void Insert(int key)


 void display();
 void heapifyUp(int index);

2. Create constructor, destructor for the MaxHeap class


3. Implement above methods
4. Write a main function to demonstrate the usage of the MaxHeap class with insertion.

Task 3

Implement a Min Heap using an array and support the deletion operation. Write a function to remove
the minimum element from the Min Heap while maintaining the heap property.

Requirements:

1. Define a MinHeap class.

Attributes of MinHeap class are

 int *heapArray;
 int capacity;
 int heapSize;

Functions for MinHeap class:

 void Insert(int key)


 void display();
 void heapifyDown(int index);
 int removeMin();

2. Create constructor, destructor for the MinHeap class


3. Implement above methods
4. Write a main function to demonstrate the usage of the MinHeap class with deletion.

Task 4

Implement a Max Heap using an array and support the deletion operation. Write a function to remove
the maximum element from the Max Heap while maintaining the heap property.

Requirements:

1. Define a MaxHeap class.

Attributes of MaxHeap class are

 int *heapArray;
 int capacity;
 int heapSize;

Functions for MaxHeap class:

 void Insert(int key)


 void display();
 void heapifyDown(int index);
 int removeMax();

1. Create constructor, destructor for the MaxHeap class


2. Implement above methods
3. Write a main function to demonstrate the usage of the MaxHeap class with deletion.

You might also like