forked from vicentebolea/dijkstra_binaryHeap_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minheap.h
70 lines (56 loc) · 1.27 KB
/
minheap.h
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
#ifndef MINHEAP_H
#define MINHEAP_H
#include <iostream>
/**
* Assignment 5 for CSE231 Data Structures
*
* 2012. 10. 8
*
* FILE: minheap.h
* DESCRIPTION: Class MinHeap, this class contain
* the declaration and definition of the class
* where is implement binary min-heap ADT.
* Also this file contains the class
* heapElem.
*
* AUTHOR: Vicente Adolfo Bolea Sanchez
* STUDENT NO: 20122901
* EMAIL: vicente.bolea@gmail.com
*/
// Heap element
class heapElem {
public:
int idx; // vertex index
float dist; // shortest path distance
heapElem(): idx(0), dist(0.0) {}
heapElem(int i, float d): idx(i), dist(d) {}
heapElem(const heapElem& h) {
idx = h.idx;
dist = h.dist;
}
};
// MinHeap class
class MinHeap {
public:
MinHeap();
~MinHeap();
void Push(const heapElem& e);
const heapElem & Top();
void Pop();
void Modify(const heapElem& e);
private:
heapElem* array;
int map[1000]; // The size is fixed since is the simpler approach
int length, capacity;
//Heap functions
void decreaseKey (int);
void increaseKey (int);
//Array functions
void resize (int);
inline void swap (int, int);
//Heap properties
inline int parent (int);
inline int leftChild (int);
inline int rightChild (int);
};
#endif