below I have a standard insert and delete function for a Min Heap, what I need to do is add a special case to both the functions when the T.num comparison happen to be equal, I then need to then compare the T.Letter where the lower Ascii value is popped first. Without the comments is the standard insert and delete, add the commented section would be my attempt to add the new feature, which, for the life of me, I don't understand why it wouldn't work.
void MinHeap<T>::insert(T& e)
{
int CurrNode = ++HeapSize;
while(CurrNode != 1 && heap[CurrNode/2].num >= e.num)
{
/*
if(heap[CurrNode/2].num == e.num)
if(heap[CurrNode/2].letter <= e.letter)
break;
*/
heap[CurrNode] = heap[CurrNode/2];
CurrNode /= 2;
}
heap[CurrNode] = e;
}
void MinHeap<T>::delet()
{
T LastNode = heap[HeapSize--];
int CurrNode = 1;
int child = 2;
while(child <= HeapSize)
{
if(child < HeapSize && heap[child].num >= heap[child+1].num)
{
/*
if(heap[child].num == heap[child+1].num)
if(heap[child].letter <= heap[child+1].letter)
child--;
*/
child++;
}
if(LastNode.num <= heap[child].num)
{
/*
if (LastNode.num == heap[child].num)
{
if (LastNode.letter <= heap[child].letter)
break;
}
else
*/
break;
}
heap[CurrNode] = heap[child];
CurrNode = child;
child *= 2;
}
heap[CurrNode] = LastNode;
}