Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 932267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:38:21+00:00 2026-05-15T20:38:21+00:00

below I have a standard insert and delete function for a Min Heap, what

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:38:22+00:00Added an answer on May 15, 2026 at 8:38 pm

    You can simply overload the comparison operator for the T type, like this:

    bool operator >(const T &left, const T &right) {
      return left.num > right.num ||
             left.num == right.num && left.letter <= right.letter;
    }
    

    And then replace heap[CurrNode/2].num >= e.num with heap[CurrNode/2] > e.

    It is best to avoid code such as that in your commented sections because it can quickly get confusing to follow and debug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below array em_events(array( and need to insert the below foreach to
I have a standard aspx page with which I need to add another standard
I have a standard code like below to validate xml against xsd, but it
I have a standard list view setup with backbone that looks something like below.
Below I have a function that animates a div ( container ) either to
How would compilers implementing the freestanding portion of each different standard below have to
i have a function (below) which is used in my mysql abstraction class and
I have this code below: And what I need to do is to be
Issue: I have a standard subclassed NSManagedObject (see below). I have a view controller
I have a standard jQuery autocomplete setup similar to the below: $(input#autocomplete).autocomplete({ source: source,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.