The heap size should be a separately stored variable, which you manage yourself.
Whenever you remove from or add to the heap, you should decrement or increment the value appropriately.
In C++, using a vector
, you may actually be able to use the size
, since the underlying representation is an array that's at least as big as the size of the vector, and it's guaranteed to stay the same size if you call resize
with a smaller size. (So the underlying array will be the array size and the vector size will be the heap size).