-
Notifications
You must be signed in to change notification settings - Fork 0
/
hollow_heap.hpp
104 lines (81 loc) · 1.86 KB
/
hollow_heap.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef ___HOLLOW_HEAP__EZRONDRE__AEF596DS___
#define ___HOLLOW_HEAP__EZRONDRE__AEF596DS___
#ifndef NULL
#define NULL 0
#endif
template<typename K, typename T>
class CHollowHeap
{
public:
struct TNode {
TNode * second_parent;
TNode * next;
TNode * child;
int rank;
K key;
T item;
bool hollow;
};
public:
/**
* @brief Creates a new Hollow Heap structure
*/
CHollowHeap();
~CHollowHeap();
/**
* @brief Find minimum in heap
*
* @return Returns an value with a minimum key
*/
T * FindMin();
/**
* @brief Insert key / item pair into the heap
*
* @param[in] key The key
* @param[in] item The item
*/
void Insert( const K & key, const T & item );
/**
* @brief DeleteMin
*
* Deletes a minimum from a heap
*
* @return returns deleted value
*/
T DeleteMin();
/**
* @brief Melds two heaps into one.
*
* @param other heap with same types to meld from.
*
* @return returns self
*/
CHollowHeap & Meld( CHollowHeap & other );
/**
* @brief DecreaseKey of given node
*
* @param to_decrease node, witch key shold be decreased
* @param[in] key to decrease to
*/
void DecreaseKey( CHollowHeap<K,T>::TNode * to_decrease, const K & key );
/**
* @brief Delete a given node from a Heap
*
* @param to_delete node to delete
*
* @return self
*/
CHollowHeap & Delete( TNode * to_delete );
protected:
CHollowHeap & Meld( TNode * other );
private:
TNode * makeNode( const K & key, const T & item );
TNode * link( TNode * first, TNode * second);
void addChild( TNode * child, TNode * parent );
void delete_node( TNode * to_delete );
private:
TNode * m_root;
int m_count;
};
#include "hollow_heap.cpp"
#endif //___HOLLOW_HEAP__EZRONDRE__AEF596DS___