Reputation: 95
hi i have the following code which will find the minimum size queue among a vector of queues and the minimimum size queue will be used to enqueue(push)
the int everytime
std::vector<std::queue<int> > q
void enqueue(){
int min_index = 1;
std::size_t size = q.size();
for( i=2; 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)
}
now my another paradigm is to do the dequeue(pop) operation in another function(shown below), bt i need to access all vector of queues declared in enqueue() function. how can i aceess the loop of queues given in the enqueue() function?
void dequeue(){
//q.pop operation , access all the queues in the vector of queues
}
willq[i].pop(int)
; access all the queues in the enqueue function and does the pop operation?
Upvotes: 1
Views: 318
Reputation: 31952
class MotherOfAllQueues{
std::vector<std::queue<int> > q;
public:
void enqueue(int);
int dequeue();
};
Is there a problem with the obvious design?
Upvotes: 1