我有一个范例,在向量的队列循环中,如果条件对于第i个队列为真,则将该第i个队列的队列大小增加5。在这个操作之后,我需要搜索所有队列的队列大小,并在最短队列中排队。 我想要做的事,如下面的代码增加队列大小并找到最短队列
#include <vector>
#include <queue>
int min_index = 0;
std::vector<std::queue<int> > q
std::size_t size = q.size();
for(i=0; i<size; i++){
if(..) {// A condition is true
//increase the size of the ith queue by 5 more times
}
if(q[min_index].size() > q[i].size())
min_index = i; // Now q[min_index] is the shortest queue
}
q[min_index].push(int)
}
给出如何人为地增加了队列的大小,如果条件是真的吗?然后搜索队列并找到最短队列。
修订
#include <vector>
#include <deque>
int min_index = 0;
std::vector<std::deque<int> > q
std::size_t size = q.size();
for(i=0; i<size; i++){
if(...) {// A condition is true
q[i].resize(q[i].size() + 5)
}
if(q[min_index].size() > q[i].size())
min_index = i; // Now q[min_index] is the shortest queue
}
q[min_index].push(int)
}
“如何人为增加队列大小”?我希望你的意思是支持存储队列可以保存数据,但目前没有,因为除此之外,你将获得的唯一“大小”增加是项目占用,即,即。将垃圾推入队列。 – WhozCraig 2013-02-20 16:07:06
@WhozCraigSo循环'if(..){//条件为真(int j = 0; j <5; j ++)q [i] .push(0);'会做什么? – billa 2013-02-20 16:15:09