1

嗨,我有以下代码,它将在队列向量中找到最小大小的队列,并且enqueue(push)每次都会将最小大小的队列用于 int

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)
}

现在我的另一个范例是在另一个函数中执行 dequeue(pop) 操作(如下所示),bt 我需要访问在 enqueue() 函数中声明的所有队列向量。如何访问 enqueue() 函数中给出的队列循环?

void dequeue(){

//q.pop operation , access all the queues in the vector of queues

}

q[i].pop(int); 访问 enqueue 函数中的所有队列并执行 pop 操作?

4

1 回答 1

1
class MotherOfAllQueues{
    std::vector<std::queue<int> > q;
public:
    void enqueue(int);
    int dequeue();
};

Is there a problem with the obvious design?

于 2013-01-20T10:40:46.850 回答