Generalize one of the previous labs to build a min-heap or a max-heap using the same heap functions. In main() pass either compareMin or compareMax to the insertHeap function:
- minHeap.insertHeap(num, compareMin);
- maxHeap.insertHeap(num, compareMax);
You also have to update the following functions of the Heap class:
- bool insertHeap(int itemIn);
- bool deleteHeap(int &itemOut);
- void _reHeapUp(int lastndx);
- void _reHeapDown(int rootndx);
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.
Change the previous lab to display a min-heap as an indented list (level numbers included). In order to do this you will have to add two new member functions to the heap class
- void _printIndented(int index, void visit(int, int)); // A
- void printIndented(void visit(int, int)); // B
Note: One function would be sufficient(A). However, to make the call simpler, a wrapper function (B) has been added (to "hide" the root of the heap).
Another solution is to add level as a parameter to _printIndented:
- void _printIndented(int index, int level, void visit(int, int));
This program will read integers from the keyboard, insert them into a max-heap, and display them as they are deleted from the heap. Most of the code is given:
- Heap.h
- Heap.cpp
- main.cpp
Your task is to finish defining four function in Heap.cpp:
- insertHeap
- deleteHeap
- _reHeapUp
- _reHeapDown