c++priority-queuebinary-heap

C++ Keep track of items in Binary Heap


I am implementing a Max Binary Heap for a problem where I have a lot of servers. When a request occurs, the server with max current capacity will be allocated to serve and this is the reason why binary heap is used.

What I need to know is that, whenever I serve to a request, which server was allocated. I know it's the 0th element in heap but which server was the 0th element in binary heap? Server numbers are integers by the way. For example: I should be able to say "Server no 33 was allocated".


Solution

  • It has been a while but, I simply created a struct with 2 integer variables. One of the variables is the value that I implement the binary heap according to. Other one is the number I wanted to track.