Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c++;:将数组推入队列,但使用std::Queue仅弹出一个int形式的数组 我想在C++中编写BFS OpenMP!在Bfs方法中,我需要添加一个int数组(动态分配) 1int*ptrtemp; 2队列Q; 3第一个元素=Q.前()//返回前端元件 4q.pop()//弹出一个int 5 ptrtempnearch=newint[nodesArray[firstElement].numNeighbours]; 6//nodesArray[firstElement]。numNeighbours是一个int 7#pragma omp并行 8表示(i=0;…){ 9 ptrtempnearch[i]=nodesArray[firstElement]。邻居[i]; 10 } 11 Q.推送(ptrtemp)//将数组添加到队列_C++_Arrays_Queue - Fatal编程技术网

c++;:将数组推入队列,但使用std::Queue仅弹出一个int形式的数组 我想在C++中编写BFS OpenMP!在Bfs方法中,我需要添加一个int数组(动态分配) 1int*ptrtemp; 2队列Q; 3第一个元素=Q.前()//返回前端元件 4q.pop()//弹出一个int 5 ptrtempnearch=newint[nodesArray[firstElement].numNeighbours]; 6//nodesArray[firstElement]。numNeighbours是一个int 7#pragma omp并行 8表示(i=0;…){ 9 ptrtempnearch[i]=nodesArray[firstElement]。邻居[i]; 10 } 11 Q.推送(ptrtemp)//将数组添加到队列

c++;:将数组推入队列,但使用std::Queue仅弹出一个int形式的数组 我想在C++中编写BFS OpenMP!在Bfs方法中,我需要添加一个int数组(动态分配) 1int*ptrtemp; 2队列Q; 3第一个元素=Q.前()//返回前端元件 4q.pop()//弹出一个int 5 ptrtempnearch=newint[nodesArray[firstElement].numNeighbours]; 6//nodesArray[firstElement]。numNeighbours是一个int 7#pragma omp并行 8表示(i=0;…){ 9 ptrtempnearch[i]=nodesArray[firstElement]。邻居[i]; 10 } 11 Q.推送(ptrtemp)//将数组添加到队列,c++,arrays,queue,C++,Arrays,Queue,11号线现在不工作。我需要向队列添加(推送或插入)一个数组,但在第3行中,我只需要返回一个int或在pop(Queue)方法中只返回一个int。 我读了《如何》和《如何》 正在使用这条线路 queue < int* > qq; queueqq; 如果我在程序中使用这一行而不是第2行,那么第3行和第4行对我来说就不能正常工作 !!!!编辑帖子 首先将ptrtempnearch(0)添加到Q中,然后将ptrtempnearch(1)添加到Q中,然后将ptrtempnearch(2)添

11号线现在不工作。我需要向队列添加(推送或插入)一个数组,但在第3行中,我只需要返回一个int或在pop(Queue)方法中只返回一个int。 我读了《如何》和《如何》 正在使用这条线路

queue < int* > qq;
queueqq;
如果我在程序中使用这一行而不是第2行,那么第3行和第4行对我来说就不能正常工作

!!!!编辑帖子

首先将ptrtempnearch(0)添加到Q中,然后将ptrtempnearch(1)添加到Q中,然后将ptrtempnearch(2)添加到Q中,这对我来说很重要,并且。。。
我认为优先级队列很有用,但我不知道如何使用它

STL容器只能保存单一类型的数据。因此,您可以添加和删除数组,也可以添加和删除单个值。但是,也许一个队列完成了您希望执行的操作:

std::queue< std::queue< int >* > qOfQs; // create a q of ptrs to qs of ints
std::queue< int >* p_q( new std::queue<int> ); //create a q on the heap
p_q->push( 1 ); // add data to the queue
p_q->push( 2 );
p_q->push( 3 );
qOfQs.push( p_q ); // add the dynamic q to the q of qs
p_q = new std::queue<int>; // create another q on the heap
p_q->push( 4 ); // add data to the queue
p_q->push( 5 );
qOfQs.push( p_q ); // add the dynamic q to the q of qs
qOfQs.front()->pop() // removes int with value 1
std::queue*>qOfQs;//创建一个从PTR到INT的qs的q
std::queue*p_q(新std::queue)//在堆上创建一个q
p_q->推(1);//向队列中添加数据
p_q->push(2);
p_q->push(3);
qOfQs.push(p_q);//将动态q添加到q的q中
p_q=新标准::队列;//在堆上创建另一个q
p_q->推(4);//向队列中添加数据
p_q->push(5);
qOfQs.push(p_q);//将动态q添加到q的q中
qOfQs.front()->pop()//删除值为1的int

您需要确保有数据要弹出,当您处理完队列队列后,您需要遍历它并删除动态分配的队列,或者更好的是,使用智能指针。

感谢Hugh White给我的答案。这是一个非常好的主意,但仅用于串行代码

在我读了一些文章之后,我发现这些函数不是线程安全的,所以我们不能在并行区域使用这些函数


再次感谢

这段代码似乎粘贴得很糟糕。您创建了一个新的
队列
Q
并直接从中
pop
,而无需将元素推入?谢谢您的回答,但我想在循环之外添加一个数组,添加数组ptrtempnearch[i]对我来说很重要,为了添加队列(Q),首先添加ptrtempnearch[0]对我来说很重要到Q,然后将ptrtempnearch[1]添加到Q,然后将ptrtempnearch[2]添加到Q,然后。。。
std::queue< std::queue< int >* > qOfQs; // create a q of ptrs to qs of ints
std::queue< int >* p_q( new std::queue<int> ); //create a q on the heap
p_q->push( 1 ); // add data to the queue
p_q->push( 2 );
p_q->push( 3 );
qOfQs.push( p_q ); // add the dynamic q to the q of qs
p_q = new std::queue<int>; // create another q on the heap
p_q->push( 4 ); // add data to the queue
p_q->push( 5 );
qOfQs.push( p_q ); // add the dynamic q to the q of qs
qOfQs.front()->pop() // removes int with value 1