parent(
inti) {
return(i - 1) / 2; }
31 int left(
inti) {
return(2 * i + 1); }
34 int right(
inti) {
return(2 * i + 2); }
57std::cout <<
"\nOverflow: Could not insertKey\n";
67 while(i != 0 &&
harr[parent(i)] >
harr[i]) {
68std::swap(
harr[i],
harr[parent(i)]);
78 while(i != 0 &&
harr[parent(i)] >
harr[i]) {
79std::swap(
harr[i],
harr[parent(i)]);
122std::swap(
harr[i],
harr[smallest]);
137std::cout <<
h.extractMin() <<
" ";
138std::cout <<
h.getMin() <<
" ";
139 h.decreaseKey(2, 1);
140std::cout <<
h.getMin();
int * harr
pointer to array of elements in heap
int capacity
maximum possible size of min heap
void decreaseKey(int i, int new_val)
int heap_size
Current number of elements in min heap.
int main()
Main function.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4