-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchap6.hpp
53 lines (46 loc) · 1.08 KB
/
chap6.hpp
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
#ifndef CHAP_6_H
#define CHAP_6_H
#include <cmath>
#include "chap2.hpp"
struct Heap {
int heap_size=0;
std::vector<float> vals;
};
namespace chap6
{
/**
* @brief gets the index of the left child node in the heap
*
* @param index node index
* @return int
*/
int inline Left(int index){return 2 * index + 1;};
/**
* @brief gets the index of the right child node in the heap
*
* @param index node index
* @return int
*/
int inline Right(int index){return 2 * (index + 1);};
/**
* @brief gets the index of the parent node in the heap
*
* @param index node index
* @return int
*/
int inline Parent(int index){return index / 2;};
/**
* @brief Enforces the heap property as defined by the chapter
*
* @param A heap input
* @param i index of the node to heapify
*/
void MaxHeapify(Heap& A, int i);
/**
* @brief Building a max heap starting from a randomly sorted array
*
* @param A heap input
*/
void BuildMaxHeap(Heap& A);
}
#endif