好的,所以我尝试对项目的向量使用排序,所以两个相邻项目的大小是 <= 2d。所以这是我的尝试:
struct item{
long number;
long size;
};
// d is global variable.
bool check(const item& x, const item& y)
{
return ((x.size + y.size) <= (2 * d));
}
// Items is a vector of item.
sort(items.begin(), items.end(), check);
我做错了什么,或者甚至不可能使用这样的条件进行排序?