I think your problem is that you are only using a reference to the pointer in one place, but not in others. Look at the signature of BuildHeap
:
void BuildHeap(HEAP* p, ELEMENT *A)
Here, when you call BuildHeap
, a copy of the pointer passed as the first argument p
is made. Your subsequent call to Resize
modifies that copy, but the caller of BuildHeap
still has its own, unmodified pointer. You might want to change the signature of BuildHeap
(and possibly other methods) to use references as well:
void BuildHeap(HEAP*& p, ELEMENT *A)
That said, you might want to consider using a class where you use a pointer which is a member variable so you don't have to pass it around all the time manually.