### 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

 12345678910 #include #include std::vector > q int min_index = 0; std::size_t size = q.size(); for( i=0; i 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
 1234567891011121314 #include #include std::vector > q int min_index = 0; std::size_t size = q.size(); for( i=0; i 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:
 12 {} {1,2,3}
end:
 12 {42,42,42} {1,2,3}
so you need to push the number `min2 - min' times. (where min2 is the second smallest number)
@ne555
 123456789101112131415161718 #include #include std::size_t min_index = 0; std::size_t second_shortest_index = 0; std::size_t size = q.size(); for( i=0; i 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.