|
int * | harr |
| pointer to array of elements in heap
|
|
int | capacity |
| maximum possible size of min heap
|
|
int | heap_size |
| Current number of elements in min heap.
|
|
◆ MinHeap()
MinHeap::MinHeap |
( |
int |
cap | ) |
|
|
inlineexplicit |
Constructor: Builds a heap from a given array a[] of given size
- Parameters
-
[in] | capacity | initial heap capacity |
◆ decreaseKey()
void MinHeap::decreaseKey |
( |
int |
i, |
|
|
int |
new_val |
|
) |
| |
Decreases key value of key at index i to new_val
Decreases value of key at index 'i' to new_val. It is assumed that new_val is smaller than harr[i].
78 while (i != 0 &&
harr[parent(i)] >
harr[i]) {
◆ deleteKey()
void MinHeap::deleteKey |
( |
int |
i | ) |
|
Deletes a key stored at index i
This function deletes key at index i. It first reduced value to minus infinite, then calls extractMin()
◆ extractMin()
int MinHeap::extractMin |
( |
| ) |
|
to extract the root which is the minimum element
◆ getMin()
Returns the minimum key (key at root) from min heap
◆ insertKey()
void MinHeap::insertKey |
( |
int |
k | ) |
|
Inserts a new key 'k'
57 std::cout <<
"\nOverflow: Could not insertKey\n";
67 while (i != 0 &&
harr[parent(i)] >
harr[i]) {
◆ left()
int MinHeap::left |
( |
int |
i | ) |
|
|
inline |
to get index of left child of node at index i
31 {
return (2 * i + 1); }
◆ MinHeapify()
void MinHeap::MinHeapify |
( |
int |
i | ) |
|
to heapify a subtree with the root at given index
A recursive method to heapify a subtree with the root at given index This method assumes that the subtrees are already heapified
◆ right()
int MinHeap::right |
( |
int |
i | ) |
|
|
inline |
to get index of right child of node at index i
34 {
return (2 * i + 2); }
The documentation for this class was generated from the following file: