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?
I think what you’re looking for is the smallest queue in the vector
q. If so, you can do this:Also, I believe in your code,
i=1is a mistake, which I think should bei=0if you want to search the entire vector, i.e from begin to end. If you really meani=1, then you have to do this:Hope that helps.