In C++, when adding onto a minHeap, which calls the bubbleUp function, how can I lexicographically compare two things that have the same priority?
I want the value that is smaller when compared lexicographically to come first in the heap. What should be the if condition be?
If the code is something like this:
void MinHeap::bubbleUp(int pos)
{
if (pos >= 0 && vec[pos].second < vec[(pos-1)/d].second)]
{
swap(vec[pos], vec[(pos-1)/d)];
bubbleUp(vec[(pos-1)/d)];
}
else if (pos >= 0 && vec[pos].second == vec[(pos-1)/d].second)
{
if(vec[pos].first < vec[(pos-1)/d].first)
{
swap(vec[pos], vec[(pos-1)/d];
bubbleup((pos-1)/d];
}
}
}
For some reference, the vector contains pair of string and priority.