【发布时间】:2012-06-18 12:52:53
【问题描述】:
我有一个包含这种结构的双端队列。
struct New_Array {
array<array<int,4>,4> mytable;
int h;
};
在这个结构中,2 个不同的数组可能具有相同的 h 值。
deque<New_Array> Mydeque;
我也知道双端队列中有多少个不同的 h(steps 的值)。以及双端队列中有多少个结构(Mydeque.size())。
我需要为每个 h 打印一个数组。从 h=0 到 h=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 is 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 taking 1 arguments
编辑:deque 未排序。对于每个h,应打印一个array。这个array 应该是此时接近双端队列末尾的那个。
【问题讨论】:
标签: c++ arrays for-loop iterator deque