10.9 Lab: Heap - Build min/max-heaps (of integers) PDF

Title 10.9 Lab: Heap - Build min/max-heaps (of integers)
Course Beginning Programming Methodologies in C++
Institution De Anza College
Pages 5
File Size 148.3 KB
File Type PDF
Total Downloads 38
Total Views 149

Summary

This Lab assignment is about Heap - Build min/max-heaps (of integers). Construct a min-heap or a max-heap using the same heap functions as in one of the previous laboratories. A reference to a comparison feature is a hint. You pass either compareMin or compareMax to the insertHeap feature in main():...


Description

10.9 Lab: Heap - Build min/maxheaps (of integers) Class: CIS22C - Lab Assignment Lecture: 10.9 Date: 06/1/2021 Description: This Lab assignment is about Heap - Build min/max-heaps (of integers). Construct a min-heap or a max-heap using the same heap functions as in one of the previous laboratories. A reference to a comparison feature is a hint. You pass either compareMin or compareMax to the insertHeap feature in main(): Generalize one of the previous labs to build a min-heap or a max-heap using the same heap functions. Hint: a pointer to a compare function. In main() you are passing either compareMin or compareMax to the insertHeap function: minHeap.insertHeap(num, compareMin); maxHeap.insertHeap(num, compareMax);

You also have to update the following functions in the Heap class: bool bool void void

insertHeap(int itemIn); deleteHeap(int &itemOut); _reHeapUp(int lastndx); _reHeapDown(int rootndx);

This program will: read integers from the keyboard and insert them into a min-heap and a maxheap display the integers as they are deleted from the min-heap. display the integers as they are deleted from the max-heap.

main.cpp /* This */

program will read integers from the keyboard and insert them into a min-heap and a max-heap display the integers as they are deleted from the min-heap. display the integers as they are deleted from the max-heap.

#include #include "Heap.h" using namespace std; void iDisplay(int item, int level); int compareMin(int, int); int compareMax(int, int); int main() { Heap minHeap(32); Heap maxHeap(32); // build heap int num; cout num; while ( num != 0) { /* Write your code here: call insertHeap to insert num into the min-heap */ /* Write your code here: call insertHeap to insert num into the max-heap */ cin >> num; } // print items as they are deleted from the min-heap (sorted in ascending order) cout...


Similar Free PDFs