![]() |
TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Public Member Functions | |
| MinHeap (int cap) | |
| void | MinHeapify (int) |
| int | parent (int i) |
| int | left (int i) |
| int | right (int i) |
| int | extractMin () |
| void | decreaseKey (int i, int new_val) |
| int | getMin () |
| void | deleteKey (int i) |
| void | insertKey (int k) |
Private Attributes | |
| 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. | |
A class for Min Heap
Definition at line 10 of file binaryheap.cpp.
|
inlineexplicit |
Constructor: Builds a heap from a given array a[] of given size
| [in] | capacity | initial heap capacity |
Definition at line 19 of file binaryheap.cpp.
|
inline |
Definition at line 51 of file binaryheap.cpp.
| 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].
Definition at line 76 of file binaryheap.cpp.
| 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()
Definition at line 105 of file binaryheap.cpp.
| int MinHeap::extractMin | ( | ) |
to extract the root which is the minimum element
Definition at line 85 of file binaryheap.cpp.
|
inline |
| void MinHeap::insertKey | ( | int | k | ) |
Inserts a new key 'k'
Definition at line 55 of file binaryheap.cpp.
|
inline |
to get index of left child of node at index i
Definition at line 31 of file binaryheap.cpp.
| 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
Definition at line 113 of file binaryheap.cpp.
|
inline |
Definition at line 28 of file binaryheap.cpp.
|
inline |
to get index of right child of node at index i
Definition at line 34 of file binaryheap.cpp.
|
private |
maximum possible size of min heap
Definition at line 12 of file binaryheap.cpp.
|
private |
pointer to array of elements in heap
Definition at line 11 of file binaryheap.cpp.
|
private |
Current number of elements in min heap.
Definition at line 13 of file binaryheap.cpp.