在向量中搜索队列大小
search the queue sizes in a vector
我有一个范例,在这个范例中,之前的整数被排队到向量中的一个队列,搜索队列的循环,并将整数排队到队列中大小最小的队列。下面的代码显示了操作。
#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)
接下来,我试图用以下条件来扩展我的范例,即整数应该被排队到最短的队列,直到它成为队列中的最大大小。
do{
q[min_index].push(int)
} while(q[min_index].size > queue sizes in the vector loop except this queue )
如何搜索除此队列之外的队列大小循环有什么想法请帮忙!!
只需计算最大队列大小和最小索引:
int min_index = 0;
int max_size = -1;
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
if(q[i].size() > max_size)
max_size = q[i].size(); // longest queue
}
while(q[min_index].size < max_size)
{
q[min_index].push(int);
}
相关文章:
- boost::进程间消息队列引发错误
- 如果我只是不访问queue_front节点的子节点,而是将它们推到队列中呢?还是BFS吗
- 有根的二进制搜索树.保留与其父级的链接
- Android NDK传感器向事件队列报告奇怪的间隔
- C++优先级队列,按对象的唯一指针的特定方法升序排列
- 在C++中搜索嵌套多映射值
- 按对象的特定方法按升序排列的C++优先级队列
- 使用2个键的cpp-stl::优先级队列排序不正确
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- 二进制搜索树叶数问题
- 为什么二进制搜索在我的测试中不起作用
- 正在尝试重载二进制搜索树分配运算符
- c++binary_search函数排序数组(流行名称搜索)出现问题
- 我是否需要在下一次转移时将所有权*转移回转移队列
- 向量上的线性搜索
- 是否有一种有效的方法来搜索队列中的关键字并覆盖其值
- C++BF使用指针队列进行搜索
- 如何使用队列从C++中的每个节点中搜索元素
- 搜索并找到最短的队列,并在某些条件后搜索
- 在向量中搜索队列大小