我有一个包含这种结构的双端队列。
struct New_Array {
array<array<int,4>,4> mytable;
int h;
};
在这个结构中,2 个不同的数组可能具有相同的 h 值。
deque<New_Array> Mydeque;
我也知道deque中有多少个不同的h(steps
的值)。以及 deque(Mydeque.size()
) 中有多少结构体。
我需要为每个 h 打印一个数组。从 h=0
到 h=steps
(steps 是已知的 int
值)。 要打印的每个数组必须越接近双端队列的末尾。
我试过这样的:
void foo(deque<New_Array> Mydeque, int steps)
for(int i=0; i<steps; i++)
{
deque<New_Array>::iterator it;
it = find(Mydeque.begin(),Mydeque.end(),i);
PrintBoard(*it); // This if a function where you enter the New_Array struct
// and it prints the array
}
}
上面给出了我:error C2679: binary '==' : no operator found which takes a right-hand operand of type 'const bool' (or there are no acceptable conversion)
或者像这样:
void foo(deque<New_Array> Mydeque, int steps)
for(int i=0; i<steps; i++)
{
deque<New_Array>::iterator it;
for(unsigned int j=0;j<Mydeque.size();j++)
{
it = find_if(Mydeque.begin(),Mydeque.end(),Mydeque[j].h==i);
PrintBoard(*it);
break;
}
}
上面给出了我:error C2064: term does not evaluate to a function takeing 1 arguments
编辑:deque
未排序。对于每个 h
,都应打印一个 array
。此数组
应该是此刻 更接近双端队列末尾的那个。
最佳答案
记住最后一个值并跳过:
assert(!Mydeque.empty());
int old_h = Mydeque[0].h + 1; // make sure it's different!
for (std::size_t i = 0, end != Mydeque.size(); i != end; ++i)
{
if (Mydeque[i].h == old_h) continue;
print(Mydeque[i]);
old_h = Mydeque[i].h;
}
关于c++ - 打印结构双端队列中的第一个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11083308/