compare queue sizes in a vector

I have a paradigm where a integer before gets enqueued to a queue in a vector, the loop of queues is searched and integer is enqueued to a queue which has minimum size among the queues. the following code shows the operation

1
2
3
4
5
6
7
8
9
10
#include <vector> 
#include <queue> 
std::vector<std::queue<int> > q
int min_index = 0;
std::size_t size = q.size();
for( i=0; i<size; i++){ //accessing loop of queues
    if(q[min_index].size() > q[i].size())
        min_index = i; // Now q[min_index] is the shortest queue
} 
q[min_index].push(int)


next i am trying to extend my paradigm with the condition, that the integers should be enqueued to the shortest queue until the count of the shortest queue is less than or equal to count of any another queues in the loop of queues.

i want to do something like the code shown below
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <vector> 
#include <queue> 
std::vector<std::queue<int> > q
int min_index = 0;
std::size_t size = q.size();
for( i=0; i<size; i++){ //accessing loop of queues
    if(q[min_index].size() > q[i].size())
        min_index = i
//p=std::size(q.begin(),q.end(),size);
}
//while(q[min_index].size <= any other queue size in the loop leaving this shortest queue)
{
    q[min_index].push(int);
}


any ideas to implement this logic, will be grateful!!
Last edited on
Is the question clear??
You could give an example.

start:
1
2
{}
{1,2,3}
end:
1
2
{42,42,42}
{1,2,3}
so you need to push the number `min2 - min' times. (where min2 is the second smallest number)
@ne555
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <vector> 
#include <queue> 
std::size_t min_index = 0;
std::size_t second_shortest_index = 0;
std::size_t size = q.size();
for( i=0; i<size; i++){ //accessing loop of queues
    if(q[min_index].size() > q[i].size()) {
        second_shortest_index = min_index; 
        min_index = i; // Now q[min_index] is the shortest queue
    } else if (q[second_shortest_index].size() > q[i].size()) {
        second_shortest_index = min_index;
    }
} 
while(q[min_index].size <= q[second_shortest_index].size() )
    {
        q[min_index].push(int);

}


will this code work for the paradigm i said above
No, line 11 is incorrect
Topic archived. No new replies allowed.