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 6691559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:45:57+00:00 2026-05-26T05:45:57+00:00

Consider a std::priority_queue where N elements have the same priority. Now consider some pop()

  • 0

Consider a std::priority_queue where N elements have the same priority. Now consider some pop()s and push()s of elements with any priority, so that the resulting queue consists of all those N elements mentioned above plus M new elements, where all the N+M elements have the same priority.

Does a following pop() guarantee that the removal of the top element follows a FIFO order in which the first inserted element is removed first?

Another question is how can I find an element and remove it from a priority queue? (a short examples is appreciated)

  • 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-26T05:45:57+00:00Added an answer on May 26, 2026 at 5:45 am

    I don’t think there is any such guarantee. According to to sgi’s docs, it depends on the underlying data structure.

    I think most common implementations use a heap. Pushing and popping any item on a heap simply updates the elements in it in such a way that there is no node where its children are larger than the parent (for max heap). In the case where both children have the same priority and one of them must take the place of the parent, there is no distinction made on choosing which node to promote. So it is entirely up to the implementation to pick the left or the right node.

    If you really need to have the nodes in FIFO order if all priorities are equal, pass in a comparison function that first orders by priority and breaks ties by using a value stored in the object that holds the number of objects pushed into the priority_queue before it.

    int cmp(my_object a, my_object b){
        if (a.priority!=b.priority) return a.priority<b.priority;
        else return a.index<b.index;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code: typedef std::vector<int> cont_t; // Any container with RA-iterators typedef cont_t::const_iterator
Consider the following code: std::string my_error_string = Some error message; // ... throw std::runtime_error(std::string(Error:
I have a function that reads user input from std::cin, and I want to
Consider a class A having a member x and a std::vector< A >. Now
Consider the following code: uint32_t x = ~uint8_t(0); std::cout << x << std::endl; Now,
I have the following problem. Consider the classes class face { virtual std::vector<ptr>& get_vertices(void)
Consider this problem: I have a program which should fetch (let's say) 100 records
Consider this line: std::wcout << Hello World!; Is it OK to pass char* or
Consider the following: std::vector<int> vec(1); // vector has one element std::fill(vec.begin(), vec.begin(), 42); std::fill(vec.begin()+1,
For a specific example, consider atoi(const std::string &) . This is very frustrating, since

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.