Your scope for right
is incorrect.
if(left+1<=last) int right = child+1;
The identifier right
only exists inside this if-block, so you cannot use it outside. You need to decide what is correct in this case. If that condition left+1<=last
is not true, should you still execute the remaining code in the function? If so, you need to declare right
outside (at the same scope level as left
), and give it an appropriate value.
I expect you intended something like this:
if(left+1 <= last) {
int child = left;
int right = left+1;
if ((heap[right]->broj) > (heap[left]->broj))
child = right;
if (heap[parent]->broj < heap[child]->broj) {
exchange(heap[parent], heap[child]);
reheapDown(heap, child, last);
}
}