Skip to content

Commit cc7793c

Browse files
committed
Fix bugs in heap
1 parent 943b52a commit cc7793c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

include/heap.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace alg {
6161
public:
6262
Heap(int max) {
6363
m_size = 0;
64-
m_max = max+1;
64+
m_max = max;
6565
m_heap = new elem[m_max];
6666
};
6767

@@ -101,7 +101,7 @@ namespace alg {
101101
inline void clear() { m_size = 0; }
102102

103103
bool contains(const T & data) {
104-
for(int i=1;i<=m_size;i++) {
104+
for(int i=0;i<m_size;i++) {
105105
if(m_heap[i].data== data) return true;
106106
}
107107
return false;
@@ -166,7 +166,7 @@ namespace alg {
166166
}
167167

168168
int j = j1;
169-
int j2 = j1+1; // left child
169+
int j2 = j1+1; // right child
170170
if (j2 < n && !less(j1,j2)) {
171171
j = j2; // choose the minium one.
172172
}

0 commit comments

Comments
 (0)