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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:36:23+00:00 2026-06-17T11:36:23+00:00

I have a paradigm which has one queue per thread. I wish to find

  • 0

I have a paradigm which has one queue per thread. I wish to find the minimum size queue, among the number of queues, which i did with the following code.

std::vector<std::queue<task> > q;

int min_value = INT_MAX;
std::size_t size = q.size();
for( i=1; i<size; i++){ //accessing loop of queues
  if(min_value > q[i].size())
    min_value = q[i].size();
}

now i wish to do a additional operation in this, every time only the minimum size queue (found from the above code) should enqueue the task.

q.get (min_value)
q.push(task) // will this one, does the required operation?
  • 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-06-17T11:36:23+00:00Added an answer on June 17, 2026 at 11:36 am

    I think what you’re looking for is the smallest queue in the vector q. If so, you can do this:

    auto cmp = [](std::queue<task> const & a, std::queue<task> const & b) {  
                   return a.size() < b.size(); 
               };
    
    //note q is a std::vector of std::queue
    auto min_queue = std::min_element(q.begin(), q.end(), cmp);
    
    min_queue->push(item);//min_queue is the iterator to the smallest queue
    

    Also, I believe in your code, i=1 is a mistake, which I think should be i=0 if you want to search the entire vector, i.e from begin to end. If you really mean i=1, then you have to do this:

    auto min_queue = std::min_element(q.begin() + 1, q.end(), cmp);
    

    Hope that helps.

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

Sidebar

Related Questions

Have deployed numerous report parts which reference the same view however one of them
On windows, each thread has a message queue, and each message queue will process
I have a simple UIViewController derived controller which has UITextFields. Also using IB, I
I have been using C++ and Java for several years now. One thing which
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
At our organization we have a SQL Server 2005 database and a fair number
Say I have a trait that has two lists. Sometimes I'm interested in the
I have a class called FooJob() which runs on a WCF windows service. This
I have a number of quasi-related projects that I want to version control. In

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.