-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriverProgram.cpp
More file actions
63 lines (48 loc) · 1.91 KB
/
DriverProgram.cpp
File metadata and controls
63 lines (48 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*==============================================================================
Program: DriverProgram8.cpp
Programmer: David Torrente
Program Description: This program will ask the user to enter the size of an
array to populate with values. The array will then be
converted into a heap, and again sorted in ascending
order. Each version of the array is displayed to the
console. Note: populateRandom is commented out in the
driver.
==============================================================================*/
#include <iostream>
#include "Heap.h"
using namespace std;
int main()
{
int arraySize;
int * array;
char option;
cout<<"Welcome to the heapify program."<<endl;
cout<<"Press 'h' or 'H' to create an array and sort it or any other key to quit."<<endl;
cout<<"Option: ";
cin>>option;
while (option == 'h' || option == 'H')
{
cout<<"Enter array size greater than 0: ";
cin>>arraySize;
while(arraySize<=0)
{
cout<<"Invalid input. Please enter an array size greater than 0: ";
cin>>arraySize;
}
array = new int[arraySize + 1];
populateArray(array, arraySize);
displayArray(array, arraySize);
cout<<"----------heaping----------"<<endl;
heapify(array, arraySize);
displayArray(array, arraySize);
cout<<"----------heaping sorted----------"<<endl;
heapSort(array, arraySize);
displayArray(array, arraySize);
delete [] array;
cout<<"Press 'h' or 'H' to create an array and sort it or any other key to quit."<<endl;
cout<<"Option: ";
cin>>option;
}//END While
system("pause");
return 0;
}