1: // Created by Frank M. Carrano and Timothy M. Henry.
2: // Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.
4: template<class ItemType>
5: ArrayMaxHeap<ItemType>::
6: ArrayMaxHeap(const ItemType someArray[], const int arraySize):
7: itemCount(arraySize), maxItems(2 * arraySize)
8: {
9: // Allocate the array
10: items = std::make_unique<ItemType[]>(maxItems);
11:
12: // Copy given values into the array
13: for (int i = 0; i < itemCount; i++)
14: items[i] = someArray[i];
15:
16: // Reorganize the array into a heap
17: heapCreate();
18: } // end constructor
20: template<class ItemType>
21: void ArrayMaxHeap<ItemType>::heapCreate()
22: {
23: for (int index = itemCount / 2 - 1; index >= 0; index--)
24: {
25: heapRebuild(index);
26: } // end for
27: } // end heapCreate