cis22c/07-heaps/main.cpp
Iurii Tatishchev 0ca7ce28fd
10.6 Lab: Heap - Build a max-heap (of integers)
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
2024-05-28 18:33:44 -07:00

41 lines
795 B
C++

/*
This program will read integers from the keyboard,
insert them into a max-heap, and display them as
they are deleted from the heap.
*/
#include <iostream>
#include "Heap.h"
using namespace std;
int main() {
Heap heap;
// build heap
int num;
cout << "Enter integers [0 - to stop]" << endl;
cin >> num;
while (num != 0) {
heap.insertHeap(num);
cin >> num;
}
cout << "Heap capacity: " << heap.getSize() << endl;
cout << "Heap actual number of elements: " << heap.getCount() << endl;
// print items as they are deleted from the heap (sorted)
if (heap.isEmpty()) {
cout << "N/A";
}
while (!heap.isEmpty()) {
heap.deleteHeap(num);
cout << num << " ";
}
cout << endl;
return 0;
}